如何为进度对话框创建两个按钮?

时间:2017-09-17 07:29:09

标签: android button progressdialog

我在代码下面有一个进度对话框:

 ProgressDialog pDialog = new ProgressDialog(activity);
            pDialog.setMessage("Please wait ...");
            pDialog.setIndeterminate(false);
            pDialog.setMax(100);
            pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            pDialog.setCancelable(true);
            pDialog.setButton(ProgressDialog.BUTTON_NEUTRAL,
                    "Hide",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            pDialog.dismiss();
                        }
                    });
            pDialog.show();

我想为progrss对话框创建两个按钮,如何为进度对话框创建两个按钮?

1 个答案:

答案 0 :(得分:0)

我们可以使用under code:

为ProgressDialog创建两个按钮
    ProgressDialog myDialog = new ProgressDialog(this);
    myDialog.setMessage("Loading...");
    myDialog.setCancelable(false);
    myDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    myDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // your code
        }
    });
    myDialog.show();