我做了一個5位圖的ArrayList。爲了創建一個ArrayList,我創建了自己的類。在gridview中顯示圖像。當我點擊網格查看項目時,BitmapFactory.decodeFile()返回null,因爲項目的位置沒有正確返回。下面是代碼BitmapFactory.decodefile返回null?
Items.class
public class Items {
final String name;
public final int drawableId;
public Items(String name, int drawableId) {
this.name = name;
this.drawableId = drawableId;
}
}
ArrayList和添加圖像在它
ArrayList<Items> bitmaps = new ArrayList<Items>();
bitmaps.add(new Items("image_name", R.drawable.image1));
在示出圖像
ArrayList<Items> _bitmaps;
.....
String itemPosition = _bitmaps.get(position).toString();
Log.d("POS", "Item Position: " + itemPosition);
Bitmap bitmap = BitmapFactory.decodeFile(itemPosition, options);
imgDisplay.setImageBitmap(bitmap);
通知的Log.d.的時間爲GridView的第一項即位置0,它返回,
08-31 02:11:47.125: D/POS(943): Item Position: [email protected]
您是否嘗試過清理您的項目? – 2014-08-30 21:58:09
是的。但是同樣的錯誤 – user3864752 2014-08-30 22:09:50
你可以發佈'getView'嗎? – mmlooloo 2014-08-31 02:06:09