У меня есть окно предупреждения, созданное с помощью следующего кода:
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);
}
Но программа проверяет, как только я нажимаю ок ... без отображения других сообщений.