Thank you all for advices. I solved my problem and a new one.
Thank you Alex for advice, i knew about localization in android, but it is not
what i need. In my application flag image and some text have to change
depending on the country choosen not the locale set on the platform.
I found how to set text for textView's based on a custom configuration, maybe
it helps you.
I used something like this:
TextView countryName=(TextView)findViewById(R.id.TextView01);
countryName.setText(getResources().getIdentifier("country_"+"uk", "string"
,getPackageName() ));
and i have saved in values/strings.xml
<string name="country_uk">United Kingdom</string>
<string name="country_ro">Romania</string>
<string name="country_us">United States</string>
<string name="country_de">Deutschland</string>
If anybody has a better solution, are welcome to post it.
Good luck,
Lidy
--- On Wed, 8/25/10, Alex <[email protected]> wrote:
From: Alex <[email protected]>
Subject: [android-developers] Re: How can i set background image for an
ImageView dynamically???
To: "Android Developers" <[email protected]>
Date: Wednesday, August 25, 2010, 9:16 AM
Read about resource qualifiers in the Android Dev Guide:
http://developer.android.com/guide/topics/resources/localization.html
I have a releated problem. I would like to choose resources based on
a custom configuration, but there doesn't seem to be a way to use the
built-in resource qualifiers for this.
On Aug 25, 10:01 am, Lidy <[email protected]> wrote:
> Hello guys,
>
> I have the following question.
> I need to use R.drawable.id's dinamicaly, depending on the country
> choosen, more precisely,depending on a "country" variable.
> For example, my screen contains a country flag. If the Deutschaland is
> the choosen country, i have to display something like this:
>
> ImageView flag;
> flag=(ImageView)findViewById(R.id.ImageView01);
> flag.setBackgroundResource(R.drawable.flag_de);
>
> Inside android application, in "res/drawable-hdpi" i have saved all
> needed flags with the following names: flag_de.jpg, flag_uk.jpg,
> flag_ro.jpg and so on.
>
> How can i set background image for this "flag" value dynamically?????
> If i use the following way, there are too mush code:
>
> if (country.equals("DE") {
> flag.setBackgroundResource(R.drawable.flag_de);} else if
> (country.equals("UK")) {
>
> flag.setBackgroundResource(R.drawable.flag_uk);} else if
> (country.equals("RO")) {
>
> flag.setBackgroundResource(R.drawable.flag_ro);
>
> }
>
> I want to create somehow "R.drawable.flag" by appending the country
> extension "de" .
>
> String countryFlag="flag_"+mySource.countryExtension ; //something
> like flag_DE
> countryFlag=countryFlag.toLowerCase(); //
> =flag_de
> flag.setBackgroundResource(R.drawable.countryFlag); // of
> course, it's not working
>
> Could anyone give me a suggestion please ?
> Thank you
> Lidy
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en