Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Universal Image Loader gridview blinks after notifyDataSetChanged call

I'm using UIL with this config to load image from 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 GridView so after I consider any item selected I call notifyDataSetChanged to make my selectionOverlay visible. And after this call all images start reloading nd this causes GridView to blink. How can I avoid this?

like image 485
Lingviston Avatar asked Sep 30 '13 20:09

Lingviston


1 Answers

I don't think that you should call notifyDataSetChanged in this situation.

Calling notifyDataSetChanged on adapter tells ListView / GridView that your data is changed you should refresh your self. So when you call this method it reload itself and getView() of adapter is called. This is why UIL starts loading images. (Actually all view of row reloads) because this is written in getView().

For accessing row view and it's data you can use setOnItemClickListener of your GridView. You will get sufficient parameters in this method and so you can work with it accordingly.

I hope this helps. Thanks

like image 55
Zealous System Avatar answered Oct 04 '22 04:10

Zealous System