2

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;
}
6
  • how can I enable it and how can use it, because I enabled caching Commented Sep 19, 2014 at 14:36
  • so how, you know that it is downloaded again? ... the server can be a problem fx it not reacts on If-Modified-Since or other caching related headers Commented Sep 19, 2014 at 14:37
  • imageview not show anything until download image again Commented Sep 19, 2014 at 14:38
  • sometimes take a while to decode bitmab from disk cache too Commented Sep 19, 2014 at 14:39
  • because I enabled caching how? i don't see code related to this in your question Commented Sep 19, 2014 at 14:41

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your code, its work but I surprise because I use cache in memory but it download again. also before I use cache on disk but again it download, but I thinks you use bitmapConfig and it work, am I wrong ?
when you say "it download again" do you see the trace in the log ? or is it that the image just feel like it's loading ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.