This question is only about a design doubt. I would appreciate some help on it.
Basically I have 6 different ImageView's, all of them are connected to the same method called onImageViewClicked
, this method will check which of the 6 ImageViews was clicked, and launch Gallery intent
to pick a photo from gallery.
Now my problem is.....the result from the gallery intent comes on onActivityResult
method but from there, how to assign the photo to the selected ImageView???......here the code:
Method onImageViewClicked that selects ImageView and launches Gallery:
private void onImageViewClicked(View v){
switch (v.getId()){
case R.id.imgvW_1:
//something here
break;
case R.id.imgvW_2:
//something here
break;
case R.id.imgvW_3:
//something here
break;
case R.id.imgvW_4:
//something here
break;
case R.id.imgvW_5:
//something here
break;
case R.id.imgvW_6:
//something here
break;
}
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
Method onActivityResult getting results from Intent:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE){
imageUri = data.getData();
//how to assign here the image to the clickedImageView?????????
}
}
---- EDIT ---- Thanks guys for the answers. All 4 answers from Ramees, Hardik Maru, Mohammed Atif and Luca Rossi look fine for me so....is any of them more convenient than the others??