Let's say I want to access to my image : R.drawable.character
I have
String drawableName = character
Is there a way to do something like that or it is forbidden in Java =>
R.drawable.drawableName
to access R.drawable.character ?
I found this but it is for sql database : How to get the image from drawable folder in android?
答案 0 :(得分:1)
int id = getResources().getIdentifier(drawableName , type, package);
This will get you the ID of the resource you are looking for. With it, you can then access the resource from the R class.