Reputation: 349
I am new to android -
I am storing images in drawable and there name in sqlite database. A subset of these images are to be used at a time. Images to be used will be decided by a query on the data base.
For example from database query produces - these strings
"pic1", "pic2" ... etc
To used them one needs the value of R.drawable.pic1.
Is there any way to retrieve the image from drawable bu its name (string containg name of the file).
Upvotes: 0
Views: 45
Reputation: 3602
try this
int id = context.getResources().getIdentifier(drawableResourceName, "drawable", context.getPackageName());
it should give you the drawable id, and then you can use like R.drawable.drawableResourceName
Upvotes: 2