I have a list view and I want to show thumbnail of video in it but everytime I scroll images download again. how can I download images once and show it. this is my code:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if(convertView == null){
rootView = mInflater.inflate(R.layout.adapter_video, parent, false);
holder = new ViewHolder();
holder.ivThumbnail = (ImageView) rootView.findViewById(R.id.ivThumbnailVideoAdapter);
rootView.setTag(holder);
}
else{
rootView = convertView;
holder = (ViewHolder)rootView.getTag();
}
imageLoader.displayImage(update.get(position).getThumbnail(), holder.ivThumbnail, option);
return rootView;
}
with UIL the download of the images is configured with DisplayImageOptions
For example :
mOptionsSimple = new DisplayImageOptions.Builder().resetViewBeforeLoading(true)
.cacheOnDisc(true)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
Here, cacheOnDisc to true saves the image on the disk, not in the cache. When you scroll the image will reload, of course because in listview cells are recycled. But with this option it will reload from the disk if it was already downloaded
You can also/or enable memoryCache BUT be carefull with this one. It can be the cause of OutOfMemoryException if the images are not managed correclty
also ImageLoaderConfiguration here is an example :
config = new ImageLoaderConfiguration.Builder(getApplicationContext()).threadPoolSize(3)
.threadPriority(Thread.NORM_PRIORITY - 1)
.tasksProcessingOrder(QueueProcessingType.FIFO)
.imageDownloader(new MyImageDownloader(mContext))
.imageDecoder(new BaseImageDecoder(false))
.discCache(new UnlimitedDiscCache(cacheDir))
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.defaultDisplayImageOptions(mOptionsSimple)
.writeDebugLogs()
.build();
In this last example the discCache is not limited which could be changed if you think it ll take too much space on the disk