Я создал одно приложение, в котором я создал галерею, а под галереей я отображаю выбранное изображение в режиме увеличения ... если у меня более 2 изображений, моя галерея отображает ошибку принудительного закрытия при нажатии на изображение из этого .. Мне нужна помощь в этом ..
Код моего приложения:
img = (ImageView) findViewById(R.id.GalleryView);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Gallery g = (Gallery) findViewById(R.id.gallery);
// set gallery to left side
MarginLayoutParams mlp = (MarginLayoutParams) g.getLayoutParams();
mlp.setMargins((int)-(metrics.widthPixels / 2 + 35), mlp.topMargin,mlp.rightMargin, mlp.bottomMargin);
imageAdapter = new ImageAdapter(this,imgarr);
g.setAdapter(imageAdapter);
if(imgarr.length > 1)
{
img.setImageURI(Uri.parse(imgarr[0]));
}
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
dialog = ProgressDialog.show(ImageGallery.this,
"Loading Image", "Please wait...", true);
img.setImageURI(Uri.parse(imgarr[position]));
dialog.dismiss();
}
});
ImageAdapter class:
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
String[] imgArray;
public ImageAdapter(Context c,String[] imgArray) {
mContext = c;
TypedArray attr = mContext
.obtainStyledAttributes(R.styleable.ImageGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.ImageGallery_android_galleryItemBackground, 0);
this.imgArray = imgArray;
attr.recycle();
}
public int getCount() {
return imgArray.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
//Toast.makeText(getApplicationContext(), "Image path from gallery : " + imgArray[position],
//Toast.LENGTH_SHORT).show();
//Bitmap bitmap = BitmapFactory.decodeFile(imgArray[position]);
Log.d("cursor lengh :", "" +imgArray[position]);
//i.setImageBitmap(bitmap);
i.setImageURI(Uri.parse(imgArray[position]));
i.setLayoutParams(new Gallery.LayoutParams(80, 70));
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
У меня есть эти ошибки:
![enter image description here](https://i.stack.imgur.com/O3pZh.png)