Universal Image Loader gridview blinks after notifyDataSetChanged call
Asked Answered
M

2

8

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?

Miliary answered 30/9, 2013 at 20:55 Comment(0)
C
3

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

Canonry answered 8/4, 2015 at 10:53 Comment(5)
Actually the problem is that images must be cached in memory so reloading must not be noticeable. This problem fixed somehow after I updated UIL.Miliary
Hi, If you have fixed issue then its good however this behavior should be avoided because of performance issue as its mentioned how notifyDataSetChanged works.Canonry
Performace is bad only if notifyDataSetChanged is called to often. For example if you're trying to update progress bar in adapter items. Also performance lack may be noticeable when you're trying to update large data set while scrolling. In other cases it is not noticeable from my experience.Miliary
Good enough. If you have solved issue then you should post answer as it may help to some one.Canonry
However my point was that if you can achieve this without using notifyDataSetChanged by getting item and applying selection to it then it could have good one.Canonry
E
0

May be this wil be useful for your requirment. https://github.com/koush/UrlImageViewHelper

use the following code to disply your image which is from 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);
                            }
                        }
                    });
Ecuador answered 9/2, 2015 at 10:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.