Issue
I have 718 drawables in the drawable-mdpi, drawable-hdpiand drawable-xhdpi folders, whose names are 1.png, 2.png... to 718.png. (They are actually Pokémon sprites)
So, depending on the Pokémon, I want to load one of them to show it. However, I cannot use the number to directly identify the R drawable ID.
Is there any way (besides of a 718-case switch or a Hashmap<Integer,Integer>) to somehow link the int IDs to the R drawable IDs?
Solution
You could try:
String sprite = "drawable/"+number;
int imageResource = getResources().getIdentifier(sprite, null, getPackageName());
The drawable is the folder where the image is in. The number is the number of the image you want. e.g. 1.png
Answered By - Howli
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.