I have a ListView and 12 ImageViews in it.
Every ImageView has different image which is loading from url. Images are shuffled and sometimes duplicated either I scroll or not.
I tried 10 other ways to solve this problem but have not succeeded.
This is the code I download and show images:
private static class ViewHolder {
    ImageView imageViewPhoto;
    Bitmap photo;
    boolean isDownloading;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder viewHolder;
    if (convertView == null) {
        // ...classical view holder and other operations...
        if (!viewHolder.isDownloading) {
            viewHolder.isDownloading = true;
            IImageDownload downloadInterface = new IImageDownload() {
                @Override
                public void onError(VolleyError error, String url) {
                }
                @Override
                public void onDownloaded(Bitmap response, String url) {
                        viewHolder.photo = response;
                    notifyDataSetChanged();
                }
            };
            imageDownloader.downloadImage(dataList.get(position).getPhotoPath(), true, downloadInterface);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    if (viewHolder.photo != null) {
        viewHolder.imageViewPhoto.setImageBitmap(viewHolder.photo);
    } else {
        viewHolder.imageViewPhoto.setImageResource(R.drawable.gray_background);
    }
}
Thanks in advance for any ideas!
Before:
imageDownloader.downloadImage(dataList.get(position).getPhotoPath(), true, downloadInterface);
Put:
viewHolder.photo.setImageBitmap(null);
This will reset the ImageView's bitmap, as it is being recycled and therefore keeping its image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With