Issue
Consider I have two images image_name1.png, image_name2.png in drawable resources of android. Now I would like set image like below,
imageView.setImage(R.drawable.image_+"MyChoice"+.png);
where MyChoice can be name1 or name2 or some string
Is that possible, or do we have any solution to achieve that?
Solution
you can do by uri
String uri = "@drawable/imname"; //imname without extension
int imageResource = getResources().getIdentifier(uri, null, getPackageName()); //get image resource
Drawable res = getResources().getDrawable(imageResource); // convert into drawble
imageView.setImageDrawable(res); // set as image
Answered By - Nirav Ranpara
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.