Android 图像视图在网格视图中单击缩略图时打开错误的图像

Android 图像视图在网格视图中单击缩略图时打开错误的图像,android,gridview,imageview,Android,Gridview,Imageview,我有一些图像显示在网格视图中。如果我在网格视图中单击缩略图,有时会打开错误的图像 请注意:并非总是如此 只有当我拍摄一张照片并转到网格视图并试图打开我最近拍摄的图像时,我才会面对这个问题。例如,我在grid view中有99张图像,我从我的相机应用程序中拍摄了第100张照片。当我在网格视图中单击第100个图像时。它会打开第98或97张照片,而不是我点击的那张。反之亦然。但其余所有的缩略图都打开良好 我的循环水课程 public void onBindViewHolder(RecyclerVie

我有一些图像显示在网格视图中。如果我在网格视图中单击缩略图,有时会打开错误的图像

请注意:并非总是如此

只有当我拍摄一张照片并转到网格视图并试图打开我最近拍摄的图像时,我才会面对这个问题。例如,我在grid view中有99张图像,我从我的相机应用程序中拍摄了第100张照片。当我在网格视图中单击第100个图像时。它会打开第98或97张照片,而不是我点击的那张。反之亦然。但其余所有的缩略图都打开良好

我的循环水课程

 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;
    }
 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;
    }
我的FullScreenImageAdapter类

 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;
    }
 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;
    }

您确定FullScreenImageAdapter类中的ImagePath和RecycleServiceAdapter类中的itemList相同吗?当第一个列表升级时,是否更新其他列表?如果路径错误,则该路径不适用于栅格视图中的其余图像。这种情况只发生在一到两张图片上,对其余的图片效果很好。是的。若你们只在第一张列表中添加了两张额外的图片,而第二张列表中并没有这些图片,第二个列表将指向与第一个列表不同的图像。只是为了确保记录/打印两个列表的大小,并确保两个列表的大小相同。简单介绍一下第一个列表和第二个列表的概念好吗?如果这是问题所在,我可以纠正谁?