Issue
How do I get a Drawable resource if I have the String (its name) as it appears in the drabale folder?
int categoryPicIndex = myCursor.getColumnIndex(CookingContract.CategoryEntry.COLUMN_PIC_CATEGORY);
String categoryPic = myCursor.getString(categoryPicIndex);
At this point I have the string that I would use to call R.drawable.___ . How can I solve the problem?
Solution
If "yourImageView"
is the ImageView and you want to set background of it and the name of image is "imageName"
yourImageView.setImageResource(context.getResources().
getIdentifier("drawable/" + imageName, null,context.getPackageName()));
But i should say sorry as it doesn't really give you drawable but it gives Resource, But i hope this will help you use the string name of drawable file.
Answered By - erluxman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.