0

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) {} } }); 

1 Answer 1

2

Well, this doesn't work this way :) You should move your code for loading and setting the bitmap to the onActivityResult method. 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 pres ctrl + 1 in Eclipse while you have selected the FileInputStream 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 :) ).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, after i put loading and setting bitmap to my onactivityresult, it worked

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.