user1420943
user1420943

Reputation: 97

display a countdown timer in the alert dialog box

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

Answers (2)

thepoosh
thepoosh

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

AntoineG
AntoineG

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

Related Questions