我有一些图像显示在网格视图中。如果我在网格视图中单击缩略图图像,有时会打开错误的图像。
请注意:并非所有时间。
这个问题只有在我拍照并转到网格视图并尝试打开我最近拍摄的图像时才会面对。例如,我在网格视图中有99个图像,我从我的相机应用程序拍摄第100张照片。当我在网格视图中单击第100个图像时。它会打开98或97张照片,而不是我点击的照片。它也发生了副作用。但是休息时所有的缩略图都打开了。
我的RecyclerViewAdapter类
public void onBindViewHolder(RecyclerViewAdapter.ViewHolder holder, int position) {
Uri uri = Uri.fromFile(new File(String.valueOf(getItem(position))));
holder.image.setImageBitmap(null);
Picasso.with(holder.image.getContext())
.load(uri)
.into(holder.image);
holder.image.setOnClickListener(new OnImageClickListener(position));
}
class OnImageClickListener extends BaseActivity implements View.OnClickListener {
int position;
public OnImageClickListener(int position){
this.position = position;
}
@Override
protected int getLayoutResource() {
return R.layout.activity_recycleview;
}
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, ImageDisplayActivity.class);
intent.putExtra("id", getPosition(position));
activity.startActivity(intent);
}
}
@Override
public int getItemCount() {
return itemList.size();
}
public Object getItem(int position) {
return this.itemList.get(getPosition(position));
}
public int getPosition(int position) {
return itemList.size() - 1 - position;
}
我的FullScreenImageAdapter类
public Object instantiateItem(ViewGroup container, int position) {
TouchImageView imageView;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout_fullscreen_image, container, false);
imageView = (TouchImageView) view.findViewById(R.id.imgDisplay);
Uri uri = Uri.fromFile(new File(String.valueOf(imagePaths.get(position))));
// If Check the path here I'm getting the path which image view is displaying, not the image path which I clicked.
Picasso.with(container.getContext())
.load(uri)
.into(imageView);
container.addView(view);
return view;
}