简体   繁体   中英

My ImageView doesn't refresh

I am trying to make an application that takes a picture and it display it on ImageView.

I succeded to make this but when I try to make a new picture the image from ImagaView is not refreshed.

For example: I push a button, an Intent to the Camera is created. I take picture 'A' which is saved on a file on the SD card at path 'fileUri' . Back in my activity mImageView1 shows the picture 'A' . Nice.It works.

I try to take a new picture 'B' , I call the Intent the picture is saved at same adress.The picture is corectly saved, but when I return in my activity mImageView1 shows the old picture 'A' . Here is the code that changes the image of the ImageView:

@Override
public void onPause(){
    super.onPause();
    ((BitmapDrawable) mImageView1.getDrawable()).setCallback(null);
}

@Override
public void onResume(){
    super.onResume();
    try{
        if(bImageSaved)
        {
            mImageView1.setImageURI(fileUri);
            mImageView1.postInvalidate();

        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
         Log.e("Image2Notes",  e.getMessage(), e);
    }

I tried different things to refresh the ImageView: mImageView1.postInvalidate(); mImageView1.draw(...); without succes.

If you have a hint I will be greatefull. Thank you,

Start your camera activity for result using startActivityForResilt(). And then override function onActivityResult (). So that when your camera activity finishes onActivityResult () function will get called. There in that function you can change the image other than changing it in onResume (). Check the activity result status in onActivityResult ().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM