在对话框之间显示ProgressDialog

时间:2016-03-26 05:09:58

标签: android timer alertdialog progressdialog

我试图通过创建一系列可在Android中完成的对话框菜单来模拟Android中的USSD交互。我试图这样做,以便在对话框之间有一个进度对话框,说明" USSD代码在运行......"但是,在单击肯定按钮时,当我尝试使用可运行的计时器运行ProgressDialog并使用名为FirstTimeUser的下一个对话框跟随它时,即使我尝试将它们与另一个计时器分开,它们也只是在另一个上面叠加一个。如何让它们连续运行而不是同时运行?下面的代码片段:

    USSDprogressDialog();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View dialogView = inflater.inflate(R.layout.number_response_dialog, null);
    builder.setView(dialogView)
            .setMessage(R.string.MainMenuText)
            // Add action buttons
            .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // Send number to next dialog
                    String choice = getMenuChoice(dialogView);
                    if (choice.equals("5")) {
                        USSDprogressDialog();
                        FirstTimeUse();
                    } else {
                        //Do nothing
                    }
                }
            })
            .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // End session
                }
            });
    AlertDialog dialog = builder.create();
    dialog.show();

带有计时器的进度对话框是:

public void USSDprogressDialog() {
    final ProgressDialog progress = new ProgressDialog(this);
    progress.setMessage("USSD code running...");
    progress.show();


    Runnable progressRunnable = new Runnable() {

        @Override
        public void run() {
            progress.cancel();
        }
    };

    Handler handler = new Handler();
    handler.postDelayed(progressRunnable, 2000);
}

欢迎任何建议!谢谢!

1 个答案:

答案 0 :(得分:1)

将FirstTimeUse()移动到对话框的progressCancel。也许你需要制作USSDprogressDialog(Runnable runnable)

相关问题