我在同一个屏幕上有三个图库。现在我已经使用不同的资源将Adapter类设置为这些画廊。但是我的所有画廊都充满了我为第三个画廊提供的最后一组输入资源。这是我的代码,Android自定义图库适配器问题
gallery_one.setAdapter(new ImageAdapter(this,Config.Jewel_Images));
gallery_two.setAdapter(new ImageAdapter(this,Config.designs_Images));
gallery_three.setAdapter(new ImageAdapter(this,Config.recommended_Images));
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
// mGalleryItemBackground = a.getResourceId(
// R.styleable.HelloGallery_android_galleryItemBackground, 0);
a.recycle();
}
public ImageAdapter(Context c,Integer gallery[]) {
mContext = c;
mImageIds=gallery;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView i = new ImageView(mContext);
pos = arg0;
i.setImageResource(mImageIds[arg0]);
i.setLayoutParams(new Gallery.LayoutParams((screen_width/3),(screen_height/6)));
i.setScaleType(ImageView.ScaleType.FIT_XY);
// i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
我不知道问题是什么,我的所有画廊都充满了我传递给适配器类的最后一个值。
任何人都可以帮助我吗?
评论库2和gallery3 setAdapter线,并检查它给你 – ingsaurabh
这表明correctly.No问题都没有。只有当我设置了多个适配器时,问题就出现了 –
那是因为你的mImageIds是全局的,如果可能的话发布你更多的代码,其中mImageIds已被声明和访问 – ingsaurabh