【问题标题】:How to load an image from sdcard to a customized listview in android?如何将图像从 sd 卡加载到 android 中的自定义列表视图?
【发布时间】:2013-11-30 11:42:17
【问题描述】:

我尝试将一张照片加载到使用 HashMap 填充的自定义列表视图中。

这里有一部分正在使用的代码......

File f = new File(Environment.getExternalStorageDirectory()+/path/Cache/photo.png");
FileInputStream is = null; 
try { 
is = new FileInputStream(f); 
} catch (FileNotFoundException e) {
Log.i("file not found","not found");
} 
Bitmap bmp =BitmapFactory.decodeStream(is);
//Bitmap bmp =BitmapFactory.decodeFile((PATH + "resene.png"));
map.put(TAG_PICTURE, bmp );
// adding HashList to ArrayList
paintShopsList.add(map);

并使用 simpleadapter 填充列表视图

adapter = new SimpleAdapter(ShopSearchActivity.this,
    paintShopsList, R.layout.list_row_search_shop, new String[] 
            {TAG_PICTURE},
    new int[] {R.id.list_image });
// updating listview

setListAdapter(adapter);

如果我使用 drawable 将图像放到 hashmap 中,它可以工作,但是当我想从 SdCard 中放入图像时发生此错误

【问题讨论】:

  • 您是否添加了从外部存储读取的权限?

标签: android listview hashmap android-sdcard simpleadapter


【解决方案1】:

不要使用新的输入流,尝试: BitmapFactory.decodeStream(getContentResolver().openInputStream(uri))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多