Android SimpleAdapter 将图像添加到 ListView

标签 android android-listview

我在使用简单适配器将图像设置为 ListView 时遇到了一点问题。我使用 sqlite 数据库中的 ID 从 sdcard 获取图像,因此 sqlite 语句有效,图像在 sdcard 上,但如果我尝试在我的 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);

最佳答案

我用这个修复了它:path = Environment.getExternalStorageDirectory() + "/MyApp/MediaCollection/"+ objectId + ".png";

关于Android SimpleAdapter 将图像添加到 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7909738/

相关文章:

android - 如何监听 ListView 上发生在列表项之外的点击事件?

android - 保存前在 Appcelerator Titanium 中调整照片大小

android - 将大图像添加到抽屉导航(SlidingMenu 库)-如何?

android - 在 ListView 中显示文件列表

java - 安卓 : Displaying information in two columns instead of one for BaseAdapter

android - 在子 Recyclerview android 中禁用滚动

android - 带有彩色行的 Mvvmcross ListView

android - 从 PreferenceScreen 到 DialogPreference

安卓对话框

android - ListView 的 getChildCount 方法不返回可见项目数的准确计数