开发者

how to display Count down clock?

开发者 https://www.devze.com 2023-02-05 02:34 出处:网络
In my ap开发者_如何转开发plication one option is there which is used to select the application trigger time that is implemented in RadioButtons like : 10 mins, 20Mins, 30mins and 60mins

In my ap开发者_如何转开发plication one option is there which is used to select the application trigger time that is implemented in RadioButtons like : 10 mins, 20Mins, 30mins and 60mins after selecting one of them the application starts at that time.. up to this working fine. But, now I want to display a count down clock after selecting one option from above from that time onwords one clock, I want to display

That will useful to user how much time remaining to trigger the application

if any body knows about this please try to help me

Thanks for reading


Something like this for short counts:

    public void timerCountDown(final int secondCount){
    Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() {           
         public void run() {                
             if (secondCount > 0){
                 //format time and display
                 counterBox.setText(Integer.toString((secondCount)));
                 timerCountDown(secondCount - 1);
             }else{
                 //do after time is up
                 removeCounterViews();
             }
         }
         }, 1000); 
     }

But this one is even better and it has two events which update the main UI thread: on tick and on finish, where tick's lenght is defined in the second parameter:

        new CountdownTimer(30000, 1000) {

        public void onTick(long millisUntilFinished) {
            mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
        }

        public void onFinish() {
            mTextField.setText("done!");
        }
     }.start();
0

精彩评论

暂无评论...
验证码 换一张
取 消