在对话框之间显示 ProgressDialog

Show ProgressDialog between Dialogs

我正在尝试通过创建一系列您可以在 Android 中浏览的对话框菜单来模拟 Android 中的 USSD 交互。我试图做到这一点,以便在对话框之间,有一个进度对话框,上面写着 "USSD code running..." 但是,单击肯定按钮后,当我尝试 运行 带有 [=21= 的 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);
}

欢迎提出任何建议!谢谢!

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