Prithniraj Nicyone
Prithniraj Nicyone

Reputation: 5111

Glide loading images each time when scrolling recyclerview

I have a RecyclerView and each item of RecyclerView is having ImageView. I am loading the image in that ImageView using Glide, when I scroll down the RecyclerView it loads images and this is fine, but when I again srcoll up the RecyclerView it again loads those images which are already been loaded. I do not want to load that images again which have already been loaded.

I am using the below code to load images using Glide

Glide.with(mActivity)
                .load(img.getmGridViewImageUrl())
                .into(imageHolder.imageView);

Upvotes: 14

Views: 11338

Answers (3)

saigopi.me
saigopi.me

Reputation: 14908

you cannot directly use this method do like below i will work

RequestOptions requestOptions = new RequestOptions();
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
Glide.with( context )
            .load( imagesModelList.get(position).getUrl() ).apply(requestOptions)
            .into( holder.imageView );
    holder.delete_item.setVisibility(View.VISIBLE);

Upvotes: 0

Koustuv Ganguly
Koustuv Ganguly

Reputation: 899

after doing this diskCacheStrategy( DiskCacheStrategy.RESULT ) also i am seeing in feedler that this is loading images from network.. i am just scrolling the grid recycler view..

Upvotes: 0

Logic
Logic

Reputation: 2258

You can cache the images either on disk or in Memory.

By default images are cached in Memory by Glide

It's also good to know that Glide will put all image resources into the memory cache by default. Thus, a specific call .skipMemoryCache( false ) is not necessary.

If you want to enable cache in disk you can use one of the following

  1. DiskCacheStrategy.SOURCE caches only the original full-resolution image.
  2. DiskCacheStrategy.RESULT caches only the final image, after reducing the resolution (and possibly transformations)
  3. DiskCacheStrategy.ALL caches all versions of the image (default behavior)

Usage :

Glide  
    .with( context )
    .load( url )
    .diskCacheStrategy( DiskCacheStrategy.ALL )
    .into( imageViewInternet );

Upvotes: 10

Related Questions