Android SimpleAdapter向ListView添加图片

3
我在使用SimpleAdapter将图片设置到ListView时遇到了一些问题。我从SD卡中获取图片,并使用SQLite数据库中的ID进行匹配,SQLite语句已经正常运行,图片也存在于SD卡中,但是当我尝试将它们设置到我的ListView时,输出结果会出错:
resolveUri failed on bad bitmap uri: android.graphics.Bitmap@40566318

在LogCat上查看日志。这是我使用的代码:

    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);
1个回答

2
我使用以下代码进行修复:path = Environment.getExternalStorageDirectory() + "/MyApp/MediaCollection/" + objectId + ".png";

1
我遇到了同样的问题,但我的方法略有不同,因为我使用了下载图像的方法,而不是位图工厂。请看一下我的问题:http://stackoverflow.com/questions/13450432/using-simpleadapter-with-image-for-listview - Sarah Phil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接