如何在android中从SD卡将图像加载到定制的listview?
我尝试将照片加载到自定义列表视图中,该视图使用HashMap填充 正在使用的代码的一部分在这里如何在android中从SD卡将图像加载到定制的listview?,android,listview,hashmap,android-sdcard,simpleadapter,Android,Listview,Hashmap,Android Sdcard,Simpleadapter,我尝试将照片加载到自定义列表视图中,该视图使用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
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,它会工作,但当我想从SD卡放入图像时,会发生此错误
不要使用新的输入流,请尝试:
BitmapFactory.decodeStream(getContentResolver().openInputStream(uri))您添加了从外部存储读取的权限吗?