Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ..

like image 563
user1420943 Avatar asked May 28 '12 07:05

user1420943


People also ask

What is the purpose of the alert dialogue 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.

How to use countdown in android?

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().


1 Answers

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();
like image 105
thepoosh Avatar answered Sep 28 '22 21:09

thepoosh