Reputation: 45
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
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
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