How To Prevent Reloading Of Images In Listview With Custom Adapter When Refresh Listview
Solution 1:
There is two solution already posted in the issue section of Universal Image Loader
.
You can use custom displayer:
newFadeInBitmapDisplayer(300) {
@OverridepublicBitmapdisplay(Bitmap bitmap, ImageView imageView, LoadedFrom loadedFrom) {
if (loadedFrom != LoadedFrom.MEMORY_CACHE) {
returnsuper.display(bitmap, imageView, loadedFrom);
} else {
imageView.setImageBitmap(bitmap);
return bitmap;
}
}
}
BitmapDisplayerdisplayer=newFadeInBitmapDisplayer(500) {
@Overridepublic Bitmap display(Bitmap bitmap, ImageView imageView,
LoadedFrom loadedFrom) {
if (loadedFrom != LoadedFrom.MEMORY_CACHE) {
returnsuper.display(bitmap, imageView, loadedFrom);
} else {
imageView.setImageBitmap(bitmap);
return bitmap;
}
}
};
DisplayImageOptionsoptions=newDisplayImageOptions.Builder()
.cacheInMemory(true).resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.thumbnail_no_image)
.showImageOnFail(R.drawable.thumbnail_no_image)
.displayer(displayer).build();
ImageLoaderConfigurationconfig=newImageLoaderConfiguration.Builder(
context).defaultDisplayImageOptions(options)
.memoryCacheSize(2 * 1024 * 1024).build();
sLoader.init(config);
Solution 2:
I faced the same problema and went with a solution as follows
Inside the getview method after declaring your imageview try the following line as first line
myImageView.setImageResource(R.drawable.adefaultimage);
this will first show a defaultimage in the imagview and will avoid duplication of images till imageloader loads the real one
Solution 3:
To achieve this :
Use android Lru cache in your list adapter. First time its looking very complex but its have more benifits.
Using Lru cache your image store in cache and when it will display then check from cache if it will exist then it will not down load and it will use from stored cache memory. You can also give cache memory size for your application and clear it.
Below have some links:
Tutorials:
http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
http://developer.android.com/reference/android/util/LruCache.html
Example :
Solution 4:
I tried above solutions but not find usefull, Finally i solved my problem by saving images from url to device(as bitmap) then get in list view from there.
Post a Comment for "How To Prevent Reloading Of Images In Listview With Custom Adapter When Refresh Listview"