我正在使用带有ImageView和TextView的Gridview。我正在使用SimpleCursorAdapter来显示SQLite数据库中的数据。我能够从数据库中显示TextView中的数据,但不能在ImageView中显示图像。我的图像路径存储在数据库的一个字段中。我需要两个选项的代码,比如在SD_CARD和res drawable文件夹中存储图像,并从数据库中读取图像路径。任何帮助都非常感谢。我搜索了这么多,但没有运气。提前致谢。我是android新手,请使用我的下面的代码并修改它。例如ImageName是test1.png,test2.png,test3.png ,,,, test98.png等。在数据库中有100个图像名称,在Fiedl_2中有相关数据。
案例3:
mCursor = DemoApplication.getDbAdapter()。getData(DemoApplication.Field_1,DemoApplication.Field_2,DemoApplication.Fiedl_3);
startManagingCursor(mCursor);
String [] from = new String [] {“ImageName”,“Field_4”,“_ id”};
int [] to = new int [] {R.id.pic,R.id.text1};
adapter = new SimpleCursorAdapter(this,R.layout.list_row_with_image,mCursor,from,to)
// gv是gridview并设置两列
gv.setNumColumns(2);
gv.setAdapter(适配器);
gv.setOnItemClickListener(本);
答案 0 :(得分:0)
如果我正确理解您的问题,您似乎需要延长SimpleCursorAdapter
或CursorAdapter
。见这个讨论:
https://codereview.stackexchange.com/questions/1057/android-custom-cursoradapter-design
您应该覆盖newView()
和bindView()
方法。