Hello guys,

I have a question on the same theme.
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



--- On Tue, 8/24/10, Doug Gordon <gordo...@gmail.com> wrote:

From: Doug Gordon <gordo...@gmail.com>
Subject: [android-developers] Some confusion on resource IDs
To: "Android Developers" <android-developers@googlegroups.com>
Date: Tuesday, August 24, 2010, 9:06 PM

I'm just getting into developing my app, which will have quite a
number of activities and thus quite a few XML files to lay out the
screens and define all the views. What I'm just seeing is that if I
assign the IDs using "@+id/name", I'll have to have a unique name for
every widget on every screen since all the symbols get defined in one
big R.java file.

Or can I just generate the definitions once in one of the XML files
and then reference them in the other layout files? For example, if I
have a TextView that I'd like to call "surname" in multiple layout
files, can I declare it one of the files using "@+id/surname" and then
simply use "@id/surname" in the other files? I assume that as long as
all the IDs are unique within a layout file, all is OK.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to