需要显示图像 - 图像名称在 SQLite (Android) 中存储为文本

Need to Display image - Image Name is stored as text in SQLite (Android)

我是 android 的新手,我在显示来自 SQLLite 的图像时遇到问题。

我在 SQLite 数据库(列名 IconName)中只存储图像名称(文本),我想使用光标显示图像。

我正在使用以下代码显示图像:

ImageView icon_pic = (ImageView) view.findViewById(R.id.icon);      
icon_pic.setImageResource(cursor.getString(cursor.getColumnIndexOrThrow("IconName")));

由于 setImageResource 需要整数值,所以我无法继续。

我试图找到堆栈溢出的答案,但不幸的是找不到任何合适的answer.Please提供任何可以帮助解决此问题的指针。

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);