ImageView does not change the image when the source changes (already uses invalidate)

I have an imageView with a given image in xml. However, when I try to change the image, ImageView never displays the second image. Instead, it displays a blank screen. I tried the code with and without invalidate (), and there were no changes.

ImageView image;
String imgPath=Environment.getExternalStorageDirectory()+"/Music/Evanescence - Discography - 1998-2011 (320 kbps)/Album's/2000 Origin (Limited Edition) (320 kbps)/Scans covers/06.jpg";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image=(ImageView)findViewById(R.id.imageView1);

    image.setImageBitmap(BitmapFactory.decodeFile(imgPath));
    if(!new File(imgPath).exists())
        Log.i("aaa","File doesnt exist");
    //select image from gallery
    //Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    //photoPickerIntent.setType("image/*");
    //startActivityForResult(photoPickerIntent, SELECT_PHOTO); 
    Log.i("aaa","DONE. img path: "+imgPath);
}
0
source share
2 answers

I think the image is too large.

On some devices, not on java.lang.OutofMemoryError, a null bitmap is displayed.

Try running code with a smaller image. If this works, you should learn how to correctly display bitmaps in Android.

(, )

0

android:background="someDrawable" xml? android:src="drawable"

setImageBitmap , setBackground(drawable)

, , . .

0

All Articles