Universal Image Loader: Can I use cache but also refresh it?

后端 未结 3 438
眼角桃花
眼角桃花 2020-12-16 04:20

I\'m loading dynamically generated images so I always want them to be up to date. But they take time to load so I also want to display a cached version while the updated one

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 05:00

    You can use the ImageLoadingListener. This interface has 4 methods to override: onLoadingStarted,onLoadingFailed,onLoadingComplete,onLoadingCancelled. In onLoadingStarted you can make the image the cached one, then on completed you change it.

    So the call would look like this:

    imgLoader.displayImage(url, myImageView,new ImageLoadingListener() 
    {
    
            @Override
            public void onLoadingStarted(String arg0, View arg1) {
                //Display cached image if it exists
    
            }
    
            @Override
            public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
                // TODO Auto-generated method stub
    
            }
    
            @Override
            public void onLoadingComplete(String arg0, View arg1, Bitmap arg2)
            {
    
                ((ImageView)arg1).setBitmapImage(arg2);
            }
    
            @Override
            public void onLoadingCancelled(String arg0, View arg1) {
                // TODO Auto-generated method stub
    
            }
    });
    

提交回复
热议问题