ImageView not refreshing/reflecting changes

前端 未结 8 1210
星月不相逢
星月不相逢 2021-01-03 22:26

I\'m using a photo picker intent to choose an image and write it to an application-private file. Most of my important source code is shown below. Once I press a button and p

8条回答
  •  臣服心动
    2021-01-03 22:42

    ImageView will not redraw if "new" URI is the same like old one. "View.invalidate()" will not work. To "force" update you can do:

    public void onResume() {
      super.onResume();
      ImageView myImageView = (ImageView)findViewById(R.id.contact_image);
      if (hasImage) {
        myImageView.setImageDrawable(null); // <--- added to force redraw of ImageView
        myImageView.setImageURI(Uri.fromFile(getFileStreamPath(TEMP_PHOTO_FILE)));
      }
    }
    

提交回复
热议问题