i have 4 diffrent imageview and try to click on all to upload diffrent images like LIcence,Rc,Profile etc . I want to uploaded image from gallery or camera dialog.. like this layout. like uper layout example
-
https://stackoverflow.com/questions/5309190/android-pick-images-from-gallery – Jaydeep Devda Jul 06 '17 at 12:36
-
Possible duplicate of [take picture from camera and choose from gallery and display in Image view](https://stackoverflow.com/questions/7304007/take-picture-from-camera-and-choose-from-gallery-and-display-in-image-view) – Darshan Kachhadiya Jul 06 '17 at 12:41
-
post your code .. – Aditya Vyas-Lakhan Jul 06 '17 at 12:45
-
i have 4 imageview and try to click all of imageview to bind diffrent images like licence ,Rc,Profile pic from caemra of gallery @JaydeepPatel – Chandan Baba Jul 06 '17 at 12:48
-
i have 4 imageview and try to click all of imageview to bind diffrent images like licence ,Rc,Profile pic from caemra of gallery @DarshanKachhadiya – Chandan Baba Jul 06 '17 at 12:51
-
https://stackoverflow.com/a/27874114/4407266 – Aditya Vyas-Lakhan Jul 06 '17 at 12:54
-
i have 4 imageview and try to click all of imageview to bind diffrent images like licence ,Rc,Profile pic from caemra of gallery @AdityaVyas-Lakhan – Chandan Baba Jul 06 '17 at 13:07
-
please see mention Layout Image @AdityaVyas-Lakhan – Chandan Baba Jul 06 '17 at 13:10
-
Please see maintion layout @Rushi – Chandan Baba Jul 06 '17 at 13:12
5 Answers
Please check my updated answer. This is just an example. Hope you understand from this
ImageView profile_pic;
private static final int SELECT_PICTURE1 = 100;
private static final int SELECT_PICTURE2 = 101;
private static final int SELECT_PICTURE3 = 102;
private static final int SELECT_PICTURE4 = 103;
picture1 = (ImageView) view.findViewById(R.id.picture1);
picture2 = (ImageView) view.findViewById(R.id.picture2);
picture3 = (ImageView) view.findViewById(R.id.picture3);
picture4 = (ImageView) view.findViewById(R.id.picture4);
picture1.setOnClickListener(this);
picture2.setOnClickListener(this);
picture3.setOnClickListener(this);
picture4.setOnClickListener(this);
@Override
public void onClick(View v) {
if (v.getId() == R.id.picture1) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE1);
}
if (v.getId() == R.id.picture2) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE2);
}
if (v.getId() == R.id.picture3) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE3);
}
if (v.getId() == R.id.picture4) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE4);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE1) {
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
String path = selectedImageUri.getPath();
Log.e("image path", path + "");
pricture1.setImageURI(selectedImageUri);
}
}
if (requestCode == SELECT_PICTURE2) {
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
String path = selectedImageUri.getPath();
Log.e("image path", path + "");
picture2.setImageURI(selectedImageUri);
}
}
if (requestCode == SELECT_PICTURE3) {
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
String path = selectedImageUri.getPath();
Log.e("image path", path + "");
picture3.setImageURI(selectedImageUri);
}
}
if (requestCode == SELECT_PICTURE4) {
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
String path = selectedImageUri.getPath();
Log.e("image path", path + "");
picture4.setImageURI(selectedImageUri);
}
}
}
}

- 2,565
- 4
- 21
- 46
-
i have 4 imageview and try to click all of imageview to bind diffrent images like licence ,Rc,Profile picture from caemra of gallery – Chandan Baba Jul 06 '17 at 13:01
-
-
-
You can declare different codes for different buttons. Then startActivityForResult and pass the code. Then check the returned code and set the image on different image views. Like I only used one button for the camera and one for the gallery. – Paras Watts Jul 07 '17 at 06:21
-
forget about buttons ,i want to click on each and every imageview and select image from camera or galery and set on imageview which imageview clicked https://stackoverflow.com/users/8091876/paras-watts – Chandan Baba Jul 07 '17 at 06:26
-
Whether click on button or ImageView . You have to declare different image picking codes and then pass those codes in startActivityForResults. For four ImageView use four different codes and get those codes in onActivityResult. Then based on returned codes set the image on ImageView – Paras Watts Jul 07 '17 at 06:30
EDIT Since you are using recyclerview or listview kind of view, you can associate tag to each viewholder and then use that tag for resolving imageview. Now you can get unique tag based on position in view. For eg in recyclerview you can use getAdapterPosition().
Associate OnClicks of each imageview with a request code. In onActivityResult resolve them and put images accordingly.

- 679
- 2
- 15
- 34
-
i was trying this but didn't get result please maintain part of code.Thanks – Chandan Baba Jul 06 '17 at 12:37
-
i have 4 imageview and try to click all of imageview to bind diffrent images like licence ,Rc,Profile pic from caemra of gallery – Chandan Baba Jul 06 '17 at 12:48
private void imageBrowse() {
if(camera){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}else{
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, PICK_IMAGE_REQUEST);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if(requestCode == PICK_IMAGE_REQUEST){
Uri picUri = data.getData();
filePath = getPath(picUri);
uri =picUri;
Log.d("picUri", picUri.toString());
Log.d("filePath", filePath);
imageView.setImageURI(picUri);
}
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}

- 337
- 4
- 15
-
when click on 2nd imageview to bind image from camera and gallery activityresult given error – Chandan Baba Jul 06 '17 at 12:46
-
i have 4 imageview and try to click all of imageview to bind diffrent images like licence ,Rc,Profile pic from caemra of gallery – Chandan Baba Jul 06 '17 at 12:47
-
I would like to suggest to refer this site, It's implementation is easy and straight forward...

- 171
- 2
- 13
In addition to the perfectly working answer by @paras, if someone wants to include the Camera option also then please refer to the below steps:
Add a dialog box which pops-up on image click and asks to chose either Camera or Gallery:
final CharSequence[] items = {"Camera", "Gallery", "Cancel"}; AlertDialog.Builder builder = new AlertDialog.Builder(PhotoActivity.this); builder.setTitle("Add Photo!"); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (items[item].equals("Camera")) { openCamera(); } else if (items[item].equals("Gallery")) { openGallery(); } else if (items[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show();
Use this method to open the Camera intent:
private void openCamera() { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, REQUEST_CAMERA); }
Now in the
onActivityResult()
method, include this to check whether the intent is from Camera:if (requestCode == REQUEST_CAMERA) { Bundle bundle = data.getExtras(); final Bitmap bitmap = (Bitmap) Objects.requireNonNull(bundle).get("data"); imageView.setImageBitmap(bitmap); }

- 27,591
- 48
- 66
- 103

- 1,433
- 2
- 17
- 22