Reputation: 23
1) Select image from gallery and image view will be updated with the picture;
2) For the first attempt, it actually works, the picture I took is displayed properly.
3) I launch the gallery again and select picture, the app goes into a blank screen and nothing happens.
I've been logging my trace and for the second time, onActivityResult is not even called despite startActivityForResult() being called already.
Here's some snippets of the relevant code:
private ImageView groupImage;
private Uri selectedImage;
groupImage = (ImageView) rootView.findViewById(R.id.groupLogo);
groupImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMG);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try{
if(requestCode == RESULT_LOAD_IMG && resultCode == Activity.RESULT_OK && data!=null){
selectedImage = data.getData();
groupImage.setImageBitmap(MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), selectedImage));
}
}catch (Exception e){
e.getStackTrace();
}
}
Upvotes: 1
Views: 740
Reputation: 20258
This line causes a trouble:
groupImage = (ImageView) rootView.findViewById(R.id.groupLogo);
In the onActivityResult
function you override a previous reference to the groupImage
, therefore on onClickListener
is not assigned to your ImageView
Upvotes: 1