How do i display a countdown timer in my alert box .i want to notify the user that the session will end in 5 minutes and show a timer running in the alert pop up box ..
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
we can set count down time after completion of time it will stop and get 0 values. onTick(long millisUntilFinished ) - In this method we have to pass countdown mill seconds after done countdown it will stop Ticking. onFinish() - After finish ticking, if you want to call any methods or callbacks we can do in onFinish().
you should have an alertDialog
for the pop-up box:
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Alert 3");
alertDialog.setMessage("00:10");
alertDialog.show(); //
new CountDownTimer(10000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
alertDialog.setMessage("00:"+ (millisUntilFinished/1000));
}
@Override
public void onFinish() {
info.setVisibility(View.GONE);
}
}.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With