【问题标题】:How to show remaining time in digital clock?如何在数字时钟中显示剩余时间?
【发布时间】:2012-04-11 16:47:32
【问题描述】:

我正在为学生创建一个应用程序。我需要显示剩余时间的数字时钟。
我在这里添加数字时钟

但它显示系统日期
我需要显示剩余时间意味着假设如果考试时间是 10 分钟,那么它必须显示
时间以相反的方式。或者我需要使用另一个时钟。 任何帮助表示赞赏。

【问题讨论】:

    标签: android clock


    【解决方案1】:

    在 onCreate 中定义此代码。

    // 5000 is the starting number (in milliseconds)
    // 1000 is the number to count down each time (in milliseconds)
    MyCount counter = new MyCount(5000, 1000);
    counter.start();
    

    CountDownTimer 的构造函数如下。

    // countdowntimer is an abstract class, so extend it and fill in methods
    public class MyCount extends CountDownTimer{
    
    public MyCount(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }
    
    @Override
    public void onFinish() {
    tv.setText(”done!”);   //TextView object should be defined in onCreate
    }
    
        @Override
    public void onTick(long millisUntilFinished) {
    tv.setText(”Left: ” + millisUntilFinished/1000);// This will be called every Second.
    
    }
    }
    

    【讨论】:

    【解决方案2】:

    看看CountDownTimer-class。

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 2018-10-12
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      相关资源
      最近更新 更多