i m using a custom dialog with an ImageView and 2 Button.
- first button to pick image from gallery
- second button to click image from camera
i want to show the image in the ImageView of the dialog..
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Dialog();
}
private void Dialog() {
// TODO Auto-generated method stub
final Dialog dialog=new Dialog(editevent1.this);
dialog.setContentView(R.layout.promote2);
ImageView image =(ImageView)findViewById(R.id.image_camera);
Button d=(Button)dialog.findViewById(R.id.button2);
Button f=(Button)dialog.findViewById(R.id.button3);
dialog.show();
d.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, 1);
}
});
f.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraintent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraintent, CAMERA_PIC_REQUEST);
}
});
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if( requestCode == CAMERA_PIC_REQUEST)
{
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image =(ImageView)findViewById(R.id.image_camera);
image.setImageBitmap(thumbnail);
}
else
{
Toast.makeText(this, "Picture NOt taken", Toast.LENGTH_LONG);
}
}
please tell me how do i get the image in ImageView which is in DialogBox for both when picked from gallery and when clicked from camera. thanks
I am not sure this can be done using a
Dialogbut instead of a custom dialog, try and use an Activity that has theUIof a dialog. To use anActivityas a dialog you need to define this in theAndroidManifest.xml:<activity android:theme="@android:style/Theme.Dialog" />EDIT for Comment
Activitywith the UI of aDialoglet’s name itDialogActivityfor our purposes), you do not have to do that since you can override theonActivityResultmethod in yourDialogActivity.Activityeither way. To pass an image that was taken by the camera app from oneActivityto another, i believe the most efficient way is to pass in theIntentas aStringthe path of that image and access the path on the secondActivity. Something like this:In the first
Activity(the callerActivity), let’s call it A:In the second
Activity(theActivitybeing called), let’s call it B: