I'm using recyclerview to show json array data. In adapter I checked if a file exists, ui elements would be different behavior like change textview color and button text. Everything is good but when scrolling down, every 5 item, one item gives same behavior with correct condition but item's condition incorrect. For example progressbar on the asynctask's onprogressupdate apply to multiple items. If click download item 1, progress apply to item number 1,6,11,...
I tried to use this.setIsRecyclable(false)
inside MyViewHolder constructor. At first glance it's seems work fine but when scroll down and back again to item, ui elements like progressbar not work's fine (before complete download, button setEnabled back to true) .
public void bind(final Context context,
final WallpaperList myWallpaperCollection, final OnItemClickListener listener) {
btnDownload=itemView.findViewById(R.id.button_download);
btnApply=itemView.findViewById(R.id.button_apply);
progressBar=itemView.findViewById(R.id.pb);
tvWallpaperId=itemView.findViewById(R.id.wallpaper_id);
imageWallpaper=itemView.findViewById(R.id.wallpaper_image);
progressBar.setMax(100);
tvWallpaperId.setText(myWallpaperCollection.getName());
int adapterPosition=getAdapterPosition();
if(interMainFile.exists()){
tvWallpaperId.setTextColor(tvWallpaperId.getContext()
.getResources().getColor(R.color.buttonbackground2));
btnDownload.setText("preview");
progressBar.setProgress(100);
} else {
btnDownload.setText("download");
progressBar.setProgress(0);
tvWallpaperId.setTextColor(tvWallpaperId.getContext()
.getResources().getColor(R.color.newColor));
}
btnDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(interMainFile.exists()){
btnDownload.setText("preview");
} else {
btnDownload.setText("download");
btnDownload.setEnabled(false);
progressBar.setProgress(0);
new DownloadTask().execute(url_to_download_main);
}
}
});
}