-1

i have an xml which has some custom tags below is the xml:

<Point 
   TestFlag="0" id="1" name="Session Introduction"
   practicenaturalfemale="practice_dummy.mp3" practicenaturalmale="practice_dummy.mp3"
   practiceukfemale="practice_dummy.mp3" practiceukmale="practice_dummy.mp3"
   practiceusfemale="practice_dummy.mp3" practiceusmale="practice_dummy.mp3">
   <PracticeText> </PracticeText>
   <PracticeFlag> 0 </PracticeFlag>

    <DownloadFiles />
    <AudioFile gid="1" id="1" name="d001_p001_01.png" type="Img" />
    <AudioFile gid="1" id="2" name="d001_ae_p001_01.png" type="mp3" />
</Point>

As you can see there is a image name "d001_p001_01.png" which is image name in audiofile tag

i need to pick the image based on this name from the drawable folder how can i acheive this.

please help

NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
Goofy
  • 6,098
  • 17
  • 90
  • 156
  • 2
    I think you are not sure what you want to do. [This](http://stackoverflow.com/questions/9156698/how-to-get-images-dynamiclly-from-drawable-folder) was your first question and now you had posted another based on that. – Lalit Poptani Feb 06 '12 at 09:43
  • can you get the name d001_p001_01.png as string in code ? – Yugandhar Babu Feb 06 '12 at 09:46
  • hello lalit i need to pick the image based on xml tag plz help – Goofy Feb 06 '12 at 09:46
  • hello babu right now i have added all the images in drawable folder and created array img[] ={R.drawable.doo1}; something like this but i need to get images based on that xml tag – Goofy Feb 06 '12 at 09:51

1 Answers1

2

Use

int id = getResources().getIdentifier("d001_p001_01", "id", getPackageName());

Note, name_of_resource should be without extension, d001_p001_01.png shall be d001_p001_01.

use this id to get actual resource:

Drawable drawable=getResources().getDrawable(id);
jeet
  • 29,001
  • 6
  • 52
  • 53