How do I add an automatic dismiss dialog after a time to the show alert function?
public void showAlert(String title, String message, Integer seconds) {
new IonAlert(context, IonAlert.SUCCESS_TYPE)
.setTitleText(title)
.setContentText(message)
.show();
}
Handler
class provides a method called postDelayed()
. It allows us to dealy an event (in your case, event is to dismiss the dialog).
public void showAlert(String title, String message, Integer seconds) {
final IonAlert ionAlertDialog = new IonAlert(context, IonAlert.SUCCESS_TYPE)
.setTitleText(title)
.setContentText(message)
.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ionAlertDialog.dismiss();
}
}, seconds ? seconds * 1000 : 5000); //default 5sec
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.