我无法在 gridview 上加载图像,它总是崩溃。记录猫消息“ArrayIndexOutOfBoundsException length=16; index=16”
这是我的代码:
public Integer[] mThumbIds = {
R.drawable.pic_1, R.drawable.pic_2,
R.drawable.pic_3, R.drawable.pic_4,
R.drawable.pic_5, R.drawable.pic_6,
R.drawable.pic_7, R.drawable.pic_8,
R.drawable.pic_9, R.drawable.pic_10,
R.drawable.pic_11, R.drawable.pic_12,
R.drawable.pic_13, R.drawable.pic_14,
R.drawable.pic_15, R.drawable.pic_16,
R.drawable.pic_17, R.drawable.pic_18,
R.drawable.pic_19, R.drawable.pic_20,
........ R.drawable.pic_96
};
代码 :
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int width = metrics.widthPixels / 6;
int height = metrics.heightPixels / 6;
ImageView i;
i = new ImageView(mContext);
i.setLayoutParams(new GridView.LayoutParams(height, height));
i.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
if(mImageSet == IMAGE_SET_ONE) {
Integer[] images1 = new Integer[16];
System.arraycopy(mThumbIds, 0, images1, 0, 16);
i.setImageResource(images1[position]);
} else if(mImageSet == IMAGE_SET_THREE) {
...........
}
return i;
}
请帮我..