Reputation: 180
I am new to android and I facing issue while displaying image from SQLLite.
I am storing only image name (text) in SQLite database (column name IconName) and I want to display the image using cursor.
I am using following code to display image:
ImageView icon_pic = (ImageView) view.findViewById(R.id.icon);
icon_pic.setImageResource(cursor.getString(cursor.getColumnIndexOrThrow("IconName")));
As setImageResource is expecting integer value so I am not able to proceed further.
I have tried to find answer onstack overflow but unfortunately not able to find any suitable answer.Please provide any pointer that can help in resolving this issue.
Upvotes: 1
Views: 441
Reputation: 724
ImageView icon_pic = (ImageView) view.findViewById(R.id.icon);
String image_name = cursor.getString(cursor.getColumnIndexOrThrow("IconName"));
int id = getResources().getIdentifier("yourpackagename:drawable/" + image_name, null, null);
icon_pic.setImageResource(id);
Upvotes: 1