Generic Image Loader gridview blinks after notifyDataSetChanged call

I use UIL with this configuration to load an image from FILE files:

BitmapDisplayer displayer = new FadeInBitmapDisplayer(500) { @Override public Bitmap display(Bitmap bitmap, ImageView imageView, LoadedFrom loadedFrom) { if (loadedFrom != LoadedFrom.MEMORY_CACHE) { return super.display(bitmap, imageView, loadedFrom); } else { imageView.setImageBitmap(bitmap); return bitmap; } } }; DisplayImageOptions options = new DisplayImageOptions.Builder() .cacheInMemory(true).resetViewBeforeLoading(true) .showImageForEmptyUri(R.drawable.thumbnail_no_image) .showImageOnFail(R.drawable.thumbnail_no_image) .displayer(displayer).build(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder( context).defaultDisplayImageOptions(options) .memoryCacheSize(2 * 1024 * 1024).build(); sLoader.init(config); 

I need to implement selection in a GridView , so after I look at any selected item, I call notifyDataSetChanged to make my Overlay selection visible. And after this call, all images will restart nd, this causes the GridView flash. How can i avoid this?

+8
android universal-image-loader adapter gridview
source share
2 answers

I do not think you should call notifyDataSetChanged in this situation.

Calling notifyDataSetChanged on the adapter tells ListView / GridView that your data has changed, you must update yourself. Therefore, when you call this method, it reloads and getView () is called. This is why UIL starts uploading images. (Actually all representations of reloading of lines) because it is written in getView ().

To access the row view and its data, you can use the setOnItemClickListener of your GridView. You will get sufficient parameters in this method, and you can work with it accordingly.

Hope this helps. Thanks

+3
source share

Maybe this will be useful for your requirement. https://github.com/koush/UrlImageViewHelper

use the following code to use your image that is associated with a URL.

 UrlImageViewHelper.setUrlDrawable(holder.imageView2, url, R.drawable.default, new UrlImageViewCallback() { @Override public void onLoaded(ImageView imageView, Bitmap b, String url, boolean loadedFromCache) { // only show the animation // if it was loaded from // network or disk... if (!loadedFromCache) { if (b != null) holder.imageView2.setImageBitmap(b); // ScaleAnimation scale = new ScaleAnimation(0, // 1, // 0, 1, ScaleAnimation.RELATIVE_TO_SELF, // .5f, ScaleAnimation.RELATIVE_TO_SELF, // .5f); // scale.setDuration(1000); // imageView.startAnimation(scale); } else { if (b != null) holder.imageView2.setImageBitmap(b); } } }); 
0
source share

All Articles