I want to take a byte
and append it to a resource ID to be able to get the image that corresponds to that numbered deck in the game. It was easy to with paths
Use getResources().getIdentifier()
from your Context
(e.g., Activity
), but please cache the result if you will use it more than once. getIdentifier()
is implemented on Resources
.
For example:
int drawableId=getResources().getIdentifier("foo"+index, "drawable", getPackageName());
would return the value of R.drawable.fooN
, where N
is the number given by index
.
For more, see this and this and this.