Reputation: 97
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 ..
Upvotes: 8
Views: 17138
Reputation: 12587
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();
Upvotes: 29
Reputation: 1247
Put a TextView in the dialog layout. Then using a Handler.postDelayed() method (or a CountDownTimer, or a Timer, or [...]), refresh the value displayed on the TextView.
Upvotes: 0