如何显示倒计时的时钟? [英] how to display Count down clock?

查看:176
本文介绍了如何显示倒计时的时钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序一个选择是有用来选择在像单选按钮来实现应用触发时间:10分钟,20分钟,30分钟和60分钟
选择其中的一个应用程序启动后,当时..到这个工作的罚款。
但是,现在我想从那个时候onwords一个时钟从上面选择一个选项后显示一个倒计时钟,我要显示

In my application 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

感谢您阅读

推荐答案

事情是这样的短期计数:

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); 
     }

但是这一次是更好的,它有两个事件,更新主UI线程:靠赊账和光洁度,其中蜱的lenght在第二个参数定义的:

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

这篇关于如何显示倒计时的时钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆