Android数据库设置ImageView
我有一个包含 5 列的数据库,其中 1 列是一个文本,其名称为 /res/drawable 文件夹。
private void fillData() {
mCursor = db2.getAllAchievements();
startManagingCursor(mCursor);
String[] from = new String[]{achHelper.ROW_NAME, achHelper.ROW_DESCRIPTION, achHelper.ROW_POINTS, achHelper.ROW_TROPHY};
int[] to = new int[]{R.id.achTitle, R.id.achDescription, R.id.achPoints, R.id.trophy};
SimpleCursorAdapter classes =
new SimpleCursorAdapter(this, R.layout.ach_row, mCursor, from, to);
setListAdapter(classes);
}
R.id.tropy 是一个 ImageView,如何根据从 achHelper.ROW_TROPHY 提取的数据设置背景图像?
I have a database with 5 columns, 1 column which is a TEXT with the name of a drawable that is /res/drawable folder.
private void fillData() {
mCursor = db2.getAllAchievements();
startManagingCursor(mCursor);
String[] from = new String[]{achHelper.ROW_NAME, achHelper.ROW_DESCRIPTION, achHelper.ROW_POINTS, achHelper.ROW_TROPHY};
int[] to = new int[]{R.id.achTitle, R.id.achDescription, R.id.achPoints, R.id.trophy};
SimpleCursorAdapter classes =
new SimpleCursorAdapter(this, R.layout.ach_row, mCursor, from, to);
setListAdapter(classes);
}
R.id.trophy is a ImageView, how can I set the background image based on the data that is being pulled from achHelper.ROW_TROPHY?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
simpleCursorAdapter 需要字符串,因此当您设置数据库时,您的 StringArray“from”必须从列
achHelper.ROW_TROPHY
获取 String 对象,它必须如下所示:因此,当您进入数据库时,您必须将 TropyImage 的 ID(整数)R.drawable.yourTropyImage 转换为字符串:
您的
String[] from、int[] to
和simpleCursorAdapter
似乎是正确的。您只需在ROW_TROPY
列中提供正确的数据类型和 ID 即可。the simpleCursorAdapter need Strings, so your StringArray "from" must get String objects from the column
achHelper.ROW_TROPHY
when you setup your database it has to look like this:So when you make your entry into your Database you have to convert the ID of your TropyImage (whitch is Integer) R.drawable.yourTropyImage to a string:
Your
String[] from, int[] to
andsimpleCursorAdapter
seem to be correct. You just must have the right DataType and ID in theROW_TROPY
column.