[英]Android SimpleAdapter add image to listview
I have a little issue with setting an image to a list view using simple adapter. 我有一个问题,使用简单的适配器将图像设置为列表视图。 I'm getting the image from sdcard using ID from sqlite database, so the sqlite statement is working, the images are on sdcard,but if I try to set them in my listview, it's giving me an output : 我使用sqlite数据库中的ID从sdcard获取图像,所以sqlite语句正在工作,图像在sdcard上,但如果我尝试在listview中设置它们,它会给我一个输出:
resolveUri failed on bad bitmap uri: android.graphics.Bitmap@40566318
on LogCat. 在LogCat上。 Here is the code I'm using to do it : 这是我用来做的代码:
String sqlite2 = "SELECT objectId FROM collectionmedias WHERE collectionId="+collId+" AND mediaType="+fronImage;
Cursor bg = userDbHelper.executeSQLQuery(sqlite2);
if (bg.getCount() == 0) {
Log.i("", "No Image file");
bg.close();
} else if (bg.getCount() > 0) {
for (bg.move(0); bg.moveToNext(); bg.isAfterLast()) {
objectId = Integer.parseInt(bg.getString(bg.getColumnIndex("objectId")));
Log.i("","objectId : "+objectId);
path = Environment.getExternalStorageDirectory()
+ "/.MyApp/MediaCollection/" + objectId + ".png";
Log.v("","path: "+path);
}
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[2*1024];
Bitmap ops = BitmapFactory.decodeFile(path, options);
hm = new HashMap<String, Object>();
hm.put(IMAGE, ops);
hm.put(TITLE, text);
hm.put(CARDS_COUNT, cardsCount +" MyApp");
items.add(hm);
}
final SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.main_listview,
new String[]{TITLE, CARDS_COUNT, IMAGE}, new int[]{ R.id.main_name, R.id.main_info, R.id.main_img});
listView.setAdapter(adapter);
我用它修复了它: path = Environment.getExternalStorageDirectory() + "/MyApp/MediaCollection/" + objectId + ".png";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.