Android 安卓警报对话框
我有一个警报框,通过以下代码创建:Android 安卓警报对话框,android,android-alertdialog,Android,Android Alertdialog,我有一个警报框,通过以下代码创建: private AlertDialog makeAndShowDialogBox(){ myDialogBox = new AlertDialog.Builder(this) //set message, title, and icon .setTitle("Terminator") .setMessage("Are you sure th
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;
}
一旦用户选择“确定”,警报框就会消失。但我希望警报框在消失之前仍要等待特定时间,因为我想更改警报框上的消息。我怎么做
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);
}
但是只要我点击ok,程序就会退出。。。没有显示其他消息。只是我的猜测: 在另一个线程中,有某种类型的
或者在具有while循环的异步任务中,当它可以继续并关闭日志时,它正在等待结果?使用自定义的
警报对话框,如下所示:
MyAlertDialog.java
public class MyAlertDialog extends AlertDialog {
public boolean allowedToDismiss = false;
public void dismiss() {
if(allowedToDismiss) {
super.dismiss();
}
}
}
在类中保存对话框的位置:
MyAlertDialog myDialogBox;
/*Code...*/
public void onClick(DialogInterface dialog, int whichButton) {
myDialogBox.allowedToDismiss = true;
/*Code...*/
}
看起来很不友好。如果有人单击关闭某个内容,而该内容却更改了对话框的文本,他们可能会感到困惑。在对话框关闭后,您可以显示祝酒词吗?@StealthRabbi:当用户单击“确定”并告诉用户等待执行某些操作时,消息会发生变化。转到以添加要在警报对话框中显示的图像和文本。。。在你的java代码中进行编辑,如下所示,我也尝试了PostDelayed和handler。。但它不起作用:|