Eevee king
Eevee king

Reputation: 45

How to empty a Imageview that has been loaded using glide

I am attempting to dynamically load an imageview when a user clicks on an object. I have tried.

 if(mImage != null){ mImage.setImageURI(null);}

            Glide.with(itemView).load(imageString).into(mImage);

imagestring is an external string that contains a url to an image. What would be the best way to do this?

Upvotes: 2

Views: 836

Answers (3)

that_guy_jrb
that_guy_jrb

Reputation: 59

Try this:

imageView.setImageBitmap(null);

Moreover you will also need to clear the Glide Cache as it stores the image.

This is how I solved this problem.

Method 1: When the URL changes whenever image changes

Glide.with(DemoActivity.this)
.load(Uri.parse("file://" + imagePath))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);

diskCacheStrategy() can be used to handle the disk cache and you can skip the memory cache using skipMemoryCache() method.

Method 2: When URL doesn't change, however, image changes

If your URL remains constant then you need to use Signature for image cache.

 Glide.with(yourFragment)
 .load(yourFileDataModel)
 .signature(new StringSignature(yourVersionMetadata))
 .into(yourImageView);

Glide signature() offers you the capability to mix additional data with the cache key.

You can use MediaStoreSignature if you are fetching content from media store. MediaStoreSignature allows you to mix the date modified time, mime type, and orientation of a media store item into the cache key. These three attributes reliably catch edits and updates allowing you to cache media store thumbs. You may StringSignature as well for content saved as Files to mix the file date modified time.

Upvotes: 0

vishal patel
vishal patel

Reputation: 294

Use this

Glide.with(this).clear(imageView);

Upvotes: 0

nik
nik

Reputation: 345

If you want to empty imageview using Glide Try this:

  imageString="";
  Glide.with(itemView).load(imageString).into(mImage);

this worked for me.

Upvotes: 2

Related Questions