Reputation: 3627
I have code like tthis:
String s = "replace__menu__" + data.imageid + ".png";
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable-hdpi", getPackageName());
The String s = instruction sets a value that is the same as one of names in my res/drawable-hdpi folder. However, the returned value sets RID to the value 0
Any idea why my code is not working? Am I doing something wrong?
Upvotes: 3
Views: 5275
Reputation: 4389
".png" is not part of a ressource name
"drawable-hdpi" I would try just 'drawable' instead
Upvotes: 3
Reputation: 20155
Try this
String s = "replace__menu__" + data.imageid; // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());
Upvotes: 6