When i press load button, im suppose to go to the galley, choose a picture and then set the imageview img to that picture. The problem is after i choose a picture in galley, the imageview does not update. However, if i press load button a second time, it take a second or two to load the galley and in that time, imageview will load the picture i previously choosen. Can someone help me so i can get imageview to refresh correctly
load.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
try {
FileInputStream in = new FileInputStream(selectedImagePath);
bMap = BitmapFactory.decodeStream(in);
img.setImageBitmap(bMap);
if (in != null) {
in.close();
}
img.invalidate();
} catch (Exception e) {}
}
});
Well, this doesn’t work this way 🙂
You should move your code for loading and setting the bitmap to the
onActivityResultmethod. Also it’s a very bad practive to catch an instance of Exception – try catching only the respective checked exception here – i.e FileNotFoundException or something -you can delete your try – catch clasuse and afterwards presctrl + 1in Eclipse while you have selected theFileInputStream in = new ...row –> choose the surround with try-catch option and eclipse will auto-generate for you the appropriate catch clause( and here I mean just the proper checked exception to be handled, not the catch clause body 🙂 ).