0

Possible Duplicate:
How can i get the resource id of an image if I know its name?

hi i want to get the id of an image,i could do this,

int id = R.layout.imagename

then i could do this

imageView.setImageResource(id)

but my question is how to get the id if i know the imagename changes at run time, so on this case how can i make R.layout."imagename" ?

Community
  • 1
  • 1
William Kinaan
  • 28,059
  • 20
  • 85
  • 118

1 Answers1

2

I just copied Francesco's answer, I hope you will up vote his answer

String mDrawableName = "myappicon";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
Community
  • 1
  • 1
Georgy Gobozov
  • 13,633
  • 8
  • 72
  • 78