Java 如何避免更改RecyclerView中选定项目的重用视图
我创建了一个android移动应用程序,在我的应用程序中,我使用了带有适配器的RecyclerView。当在recyclerview中单击该项目时,每次单击都会更改不同的背景图像,我可以单击“保存”将照片保存在手机中,并且会有一个保存的标记,表明您已保存该照片,但在我滚动之后,我看到其他项目与我在开始时单击的项目具有相同的背景图像和保存标记,即使它没有保存,这似乎是一个回收器如何工作的问题,以下是onBindViewHolder中关注此问题的部分代码 `` 那么,如何避免这个问题,只在我单击的项目中进行更改,而在其他重复使用的项目中不进行更改呢Java 如何避免更改RecyclerView中选定项目的重用视图,java,android,android-recyclerview,Java,Android,Android Recyclerview,我创建了一个android移动应用程序,在我的应用程序中,我使用了带有适配器的RecyclerView。当在recyclerview中单击该项目时,每次单击都会更改不同的背景图像,我可以单击“保存”将照片保存在手机中,并且会有一个保存的标记,表明您已保存该照片,但在我滚动之后,我看到其他项目与我在开始时单击的项目具有相同的背景图像和保存标记,即使它没有保存,这似乎是一个回收器如何工作的问题,以下是onBindViewHolder中关注此问题的部分代码 `` 那么,如何避免这个问题,只在我单击的项
WallpaperViewHolder k = (WallpaperViewHolder)holder;
final Quote w =(Quote) mRecyclerViewItems.get(position);
File file1=new File(Environment.getExternalStorageDirectory().getAbsolutePath(),R.String.APP);
File file2= new File(file1,category+w.id + ".jpg");
if (file2.exists()) {
k.iv_save_quote.setImageResource(R.drawable.ic_menu_check);
k.tv_save_quote.setText(R.string.Saved);
}
k.relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int numOfImages = 24;
images = new int[numOfImages];
images[0] = R.drawable.img36;
images[1] = R.drawable.img31;
images[2] = R.drawable.img32;
images[3] = R.drawable.img24;
images[4] = R.drawable.img8;
images[5] = R.drawable.img16;
images[6] = R.drawable.img33;
images[7] = R.drawable.img34;
images[8] = R.drawable.img35;
images[9] = R.drawable.img11;
images[10] = R.drawable.img20;
images[11] = R.drawable.img37;
images[12] = R.drawable.img21;
images[13] = R.drawable.img38;
images[14] = R.drawable.img39;
images[15] = R.drawable.img40;
images[16] = R.drawable.img41;
images[17] = R.drawable.img42;
images[18] = R.drawable.img3;
images[19] = R.drawable.img43;
images[20] = R.drawable.img7;
images[21] = R.drawable.img46;
images[22] = R.drawable.img47;
images[23] = R.drawable.img44;
k.relativeLayout.setBackgroundResource(images[imagesIndex]);
++imagesIndex; // update index, so that next time it points to next resource
if (imagesIndex == images.length)
imagesIndex = 0; // if we have reached at last index of array, simply restart from beginning
}
});