问题描述
我正在尝试通过创建一系列可以在Android中浏览的对话框菜单来模拟Android中的USSD交互.我正在尝试使其在对话框之间出现一个进度对话框,其中显示"USSD代码正在运行...".但是,单击肯定按钮后,当我尝试使用可运行的计时器运行ProgressDialog并遵循它时在下一个名为FirstTimeUser的对话框中,即使我尝试使用另一个计时器将它们分开,它们也只会在另一个对话框的上方分层.如何使它们连续而不是同时运行?下面的代码段:
I'm trying to mock up a USSD interaction in Android by creating a series of dialog menus that you can go through in Android. I'm trying to make it so that in between dialogs, there is a progress dialog that says "USSD code running..." However, upon clicking the positive button, when I try to run a ProgressDialog with a runnable timer and follow it with the next dialog called FirstTimeUser, they just layer one on top of another, even if I try to separate them with another timer. How can I make them run consecutively instead of simultaneously? Code snippets below:
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();
带有计时器的进度对话框是:
And the progress dialog with a timer is:
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);
}
任何建议都将受到欢迎!谢谢!
Any suggestions would be welcome! Thank you!
推荐答案
将FirstTimeUse()移至对话框的progressCancel.也许您需要使USSDprogressDialog(Runnable runnable)
move FirstTimeUse() to the progressCancel of the dialog. maybe you need to make USSDprogressDialog(Runnable runnable)
这篇关于在对话框之间显示ProgressDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!