Loading images in GridView using Universal Image Loader

点点圈 提交于 2019-12-01 03:30:32

I have solved the problem

I was just declaring option, but I wans't using it, so I have modified the line:

imageLoader.displayImage(basePath+immagine, iv);

into:

imageLoader.displayImage(basePath+immagine, iv, options);

and I have added in the options the method:

.cacheOnDisc(true)

Caching is not enabled by default in UIL, so if you want use the cache you should use

// Create default options which will be used for every 
//  displayImage(...) call if no options will be passed to this method
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
    ...
    .cacheInMemory()
    .cacheOnDisc()
    ...
    .build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
    ...
    .defaultDisplayImageOptions(defaultOptions)
    ...
    .build();
ImageLoader.getInstance().init(config); // Do it on Application start

And while loading image use:

// Then later, when you want to display image
ImageLoader.getInstance().displayImage(imageUrl, imageView); // Default options will be used

Another way is

DisplayImageOptions options = new DisplayImageOptions.Builder()
    ...
    .cacheInMemory()
    .cacheOnDisc()
    ...
    .build();
ImageLoader.getInstance().displayImage(imageUrl, imageView, options); 

And you can find more information here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!