ImageView not refreshing/reflecting changes

前端 未结 8 1189
星月不相逢
星月不相逢 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 23:08

    For me, it refreshed my ImageView with this

     @Override
        public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
            if (requestCode == PICK_PHOTO && resultCode == RESULT_OK && data != null && data.getData() != null) {
    
                filePath = data.getData();
    
                try {
                    mProfilePic.setImageURI(null);
                    mProfilePic.setImageURI(filePath);
                    Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
    
                    mProfilePic.setImageBitmap(imageBitmap);
    
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    
        }
    

提交回复
热议问题