As per title, how can I stop UIL from reload the image after every scroll in a ListView?
Here is how I implement the Image Loader:
public class LatestAdapter extends BaseAdapter {
...
// UIL
private ImageLoaderConfiguration config;
private File cacheDir;
private DisplayImageOptions options;
private ImageLoader imageLoader = ImageLoader.getInstance();
public LatestAdapter(Context context, ArrayList<ItemListModel> items) {
this.arrItemList = items;
this.context = context;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"JunkFolder");
else
cacheDir=context.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.placeholder)
.showImageOnFail(R.drawable.error)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
config = new ImageLoaderConfiguration.Builder(context)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.discCache(new UnlimitedDiscCache(cacheDir))
.threadPoolSize(5)
.defaultDisplayImageOptions(options)
.build();
imageLoader.init(config);
}
...
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
...
imageLoader.displayImage(nm.getThumbnail().getImage100(), vh.tvThumbnail, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String s, View view) {
}
@Override
public void onLoadingFailed(String s, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String s, View view, Bitmap bitmap) {
}
@Override
public void onLoadingCancelled(String s, View view) {
}
});
}
}
Every time I scroll the ListView (go up or down), it doesn't save the previously loaded image, instead it reloads the ImageView. How do I 'save' the image so that it doesn't flicker on every scroll?
You won't be able to save the ime. A list adapter creates the items that are displayed and some items above and below. All other items are destroyed then re-created when needed. That's the purpose of the convertView.
In ImageLoader library, even if you have cache, when the item is created, the lib looks for some cached image then displays it, or goes on network to download it.
Now, the first time your image is created, it takes some time to get it from the network and cache it.
The other times it is created, it takes time, very few time, to look in the cache and display it. But it's not instant display either...