我有一个警告框,通过下面的代码创建:Android的警告对话框
private AlertDialog makeAndShowDialogBox(){
myDialogBox =
new AlertDialog.Builder(this)
//set message, title, and icon
.setTitle("Terminator")
.setMessage("Are you sure that you want to quit?")
.setIcon(android.R.drawable.btn_star)
//set three option buttons
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "YES" goes here
functionShow(myDialogBox);
}
})//setPositiveButton
/* .setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "NO" goes here
msg = "Cancel " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})*/
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//whatever should be done when answering "NO" goes here
msg = "NO " + Integer.toString(whichButton);
txtMsg.setText(msg);
}
})//setNegativeButton
.create();
return myDialogBox;
}
警告框,只要用户选择OK消失。但是我希望警报框在消失之前仍然等待特定的时间,因为我想更改警报框中的消息。我该怎么做?
functionShow有如下定义:
void functionShow(final AlertDialog dia)
{
dia.setMessage("Generating Unique ID ... Please Wait ");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
dia.setMessage("Notyfying the user ... Please Wait");
}
}, 10000);
Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
public void run()
{
dia.setMessage("Your unique id is 0001. Kindly wait for the other person to respond");
}
}, 15000);
}
但是程序只要我点击确定检查出来......没有显示其他消息。
似乎很unintutive UI。如果有人点击关闭某些东西,而是改变对话框的文字,他们可能会感到困惑。对话框关闭后,您能否显示Toast? –
@StealthRabbi:当用户点击确定并且告诉用户等待执行一些动作时,消息改变 – Chandeep
去添加图像和文本你想要显示在你的警报对话框... http://stackoverflow.com/一个/ 10861216/1428123和编辑在你的Java代码像下面http://stackoverflow.com/a/10861174/1428123 –