问题
I wonder android support multiple dialog? Since when I first open the dialog. I allow user to click cancel, that will open one more dialog to confirm whether the user want to exit , the problem is if the user do not want to exit, the original dialog will disappear, how to fix the problem? Thanks
public static ProgressDialog showProgressDialog(final Context ctx, boolean isCancelable) {
ProgressDialog dialog = new ProgressDialog(ctx);
dialog.setCancelable(false);
dialog.setTitle(ctx.getResources().getString(R.string.system_info));
dialog.setMessage(ctx.getResources().getString(R.string.downloading));
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
if (isCancelable){
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, ctx.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder builder = new Builder(ctx);
builder.setMessage(R.string.cancel_offline_mode);
builder.setTitle(R.string.system_info);
builder.setPositiveButton(ctx.getResources().getString(R.string.confirm), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton(ctx.getResources().getString(R.string.cancel), null);
builder.create().show();
}
});
}
return dialog;
}
Update:
Here is what I would expected:
- The first dialog showing the download progress (eg. Downloaded 60% etc..)
- At the first dialog there is a cancel button, if click on it show the second dialog
- The second dialog ask whether confirm to cancel download
- If confirm, do cancel()...
- If not , return to the first dialog and show the percentage
Thanks
回答1:
This is my function in which first of all dialog open which have says "take picture","Add Video"..when you click on "take picture" then another dialoge open which have says "camera" or "gallery" etc etc..hope it's work for you.
private void popupPhotoSelector(){
Utilities.alert_video("", null,
// Utilities.alert("", null,
new AlertDialogActionSettings("Take Picture", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
overwritePhoto = true;
takePicture();
}
}),
new AlertDialogActionSettings("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
overwritePhoto = true;
openGallery();
}
}),
///////////////////// Add Video //////////////////////////////
new AlertDialogActionSettings("Add Video", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Intent intent = new Intent(getBaseContext(), Main_Vevue_Activity.class);
//startActivity(intent);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("MLI");
// set dialog message
alertDialogBuilder
.setMessage("Take Video From!")
.setCancelable(true)
.setPositiveButton("Camera",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
overwritePhoto = true;
takeVideo();
}
})
.setNegativeButton("Gallery",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
overwritePhoto = true;
openGalleryForVideo();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}),
///////////////////// Add Video End //////////////////////////////
null, false
);
}
回答2:
By dismissing second dialog you have to call first dialog by yourself and send any result data if you need.
回答3:
Try this
public void showProgressDialog(final Context ctx, boolean isCancelable) {
ProgressDialog dialog = new ProgressDialog(ctx);
dialog.setCancelable(false);
dialog.setTitle("Title dialog");
dialog.setMessage("downloading");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setProgress(0);
if(isCancelable)
{
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog2(ctx);
}
});
}
dialog.show();
}
private void showDialog2(final Context ctx) {
AlertDialog.Builder builder = new Builder(ctx);
builder.setMessage("cancel");
builder.setTitle("dialog title");
builder.setPositiveButton("cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showProgressDialog(ctx, false);
dialog.dismiss();
}
});
builder.setNegativeButton("confirm", null);
builder.create().show();
}
来源:https://stackoverflow.com/questions/22196886/show-one-progress-dialog-only-at-a-time-in-android