Hi i have my adapter for RecyclerView and i need to show a large list (different lists with images). All images i am loading into ImageView from a separate thread. Each thread for each ImageView. The problem is in that when i am changing data for my adapter and calling notifyDataSetChanged(); - sometimes the new ImageViews are displaying images from a previous data set. I understand that this is happening because of RecyclerView is reusing the ViewHolder item - in which the old thread is still downloading the old image, not new. So i am wondering how can i stop all threads when my dataset in adapter is changing. May be the approach is to put all threads into an array and stop all of them before calling notifyDataSetChanged();? But i think there are can be more elegant solutions? This is my code:
@Override
public void onBindViewHolder(ItemHolder holder, int position) {
........
holder.itemIcon.setImageResource(tree.getDefaultCover());
BitmapWorkerTask bitmapWorkerTask = new BitmapWorkerTask(holder.itemIcon, tree);
bitmapWorkerTask.execute(file);
......
}
then in my Worker task i am setting Bitmap in postExecute method
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
mIconView.setImageBitmap(result);
}