ImageView available:

<ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="wrap_content"/> 

In the code found it:

 ... ImageView imageView = (ImageView) findViewById(R.id.imgViewPreview); ... 

Further:

 imageView.setImageURI(myUri); 

Ok, the image was displayed in the ImageView, but the problem is that I have to periodically change the image in this ImageView, causing the second time

 imageView.setImageURI(myUriTwo); 

An old image remains in the ImageView. How to change the image in the ImageView?

UPD: Important note, in the imageView method setImageURI I pass the same link, i.e. the image is displayed for the first time, if all the norms, the image (jpg file) is modified by pressing the button, and the modified image must be displayed. I call the method a second time, with the same myUri (and not myUriTwo), the jpg image on the media was overwritten, and the ImageView remains the same.

Solved the problem like this:

 imageView.setImageResource(0); imageView.setImageURI(myUri); 

Most likely the image is simply cached, but my solution to the problem is more like a crutch. Any ideas? Or leave it would be quite normal (PS learning to write correctly).

    1 answer 1

    You do everything right. If you look at the source of this method:

     public void setImageURI(Uri uri) { if (mResource != 0 || (mUri != uri && (uri == null || mUri == null || !uri.equals(mUri)))) { updateDrawable(null); mResource = 0; mUri = uri; final int oldWidth = mDrawableWidth; final int oldHeight = mDrawableHeight; resolveUri(); if (oldWidth != mDrawableWidth || oldHeight != mDrawableHeight) { requestLayout(); } invalidate(); } } 

    it can be seen that the widget is redrawn only if the URI previously assigned, not null , is not identical to the one transferred and / or not assigned at all.

    Because you pass the same instance of the URI, the condition is not met and the image does not change. So yes - you must first reset the internal URI of the ImageView and only then assign it again.