Show one progress dialog only at a time in android?

徘徊边缘 提交于 2019-12-25 03:04:52

问题


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:

  1. The first dialog showing the download progress (eg. Downloaded 60% etc..)
  2. At the first dialog there is a cancel button, if click on it show the second dialog
  3. The second dialog ask whether confirm to cancel download
  4. If confirm, do cancel()...
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!