【问题标题】:Show ProgressDialog between Dialogs在对话框之间显示 ProgressDialog
【发布时间】:2016-03-26 05:09:57
【问题描述】:

我正在尝试通过创建一系列可以在 Android 中使用的对话框菜单来模拟 Android 中的 USSD 交互。我正在努力做到这一点,以便在对话框之间,有一个进度对话框显示“USSD 代码正在运行......”但是,单击肯定按钮后,当我尝试使用可运行计时器运行 ProgressDialog 并遵循它时在下一个名为 FirstTimeUser 的对话框中,即使我尝试将它们与另一个计时器分开,它们也只是将一个放在另一个之上。如何让它们连续运行而不是同时运行?代码如下:sn-ps:

    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);
}

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

【问题讨论】:

    标签: android timer android-alertdialog progressdialog


    【解决方案1】:

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

    【讨论】:

    • 我尝试按照您的建议将 FirstTimeUse 包含在 progressCancel 中,并且成功了!但是现在我有另一个问题,那就是我需要使 USSDProgressDialog 通用,以便能够将它包含在所有对话框之间,并且我有很多对话框。不过,我会努力的。谢谢!!
    • 看第二句——让USSDprogressDialog接收一个runnable
    • 啊!我明白你现在的意思了。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 2018-05-17
    相关资源
    最近更新 更多