Deleted Images in ListView with ViewHolder Template

The main question:

What is the most efficient lossless method for lazily loading remote images into a simple ListView adapter that uses the ViewHolder template?

I currently have an implementation that will first check the Bitmap HashMap SoftReference for the soft image cache version. If this fails, I will check my hard cache for a copy of the image. If this fails, I get it from the Internet. I do all this in a separate thread and in a queue to exclude simultaneous or duplicate downloads.

The problem is loading via callback. Since I use the ViewHolder template, my views are constantly being refined, and I have not found a reliable way to eliminate various images accidentally attached to my ImageViews. I make a default image by default before each load, but since the views are processed so quickly that the "old" listeners are applied to my ImageView, providing the wrong image, which is then replaced with the correct image.

The only semi-solid solution I found was to use ViewHolder itself as a listener, but that only makes the problem less obvious. This still happens when scrolling fast.

Any help would be appreciated.

Update:

https://github.com/DHuckaby/Prime

+7
source share
1 answer

I found a solution to the problem of switching images, and I provided the code snippet below. I will not accept it, though, because I do not know if this is the most effective method, which is my initial question. If this is done correctly, it will work perfectly.

public void getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { ... String imagePath = insertImageUrlHere(); Object tag = holder.userThumb.getTag(); if (tag != null && tag.equals(imagePath)) { // Do nothing } else { holder.userThumb.setTag(imagePath); holder.userThumb.setImageResource(R.drawable.default_image); AsynchronousImageLoadingUtility.load(imagePath, holder); } ... return convertView; } private static class ViewHolder implements AsynchronousImageLoadingUtilityCallback { private ImageView userThumb; @Override public void onImageLoad(String source, Bitmap image) { if (image != null && userThumb.getTag().equals(source)) { userThumb.setImageBitmap(image); } } } 
+6
source

All Articles