Reputation: 362
If I have a variable with the number associated with a gridview position (id int 14) how do I make the code below load the correct drawable? (ie hccat14)
mBitmap = getImageFromResource(getContext(), R.drawable.hccat14,w, h);
Thanks, Shannon
Upvotes: 0
Views: 253
Reputation: 3005
Here's what I use, just set the stringName
on click
imageResource = Classname.this.getResources().getIdentifier(stringName,
null, null);
mBitmap.setImageResource(imageResource);
EDIT I store the image name as packagename:drawable/imagename
in my database
Upvotes: 1
Reputation: 4339
I don't know exactly how you are trying to use it, but it should be something like this.
String resouceName = "hccat" + Integer.toString(14);
int resourceID = getResources().getIdentifier(resourceName,
"drawable", getPackageName());
Upvotes: 2