1

正在为学生创建一个应用程序。我需要显示剩余时间的数字时钟。
在这里我添加了数字时钟
在此处输入图像描述
,但它显示系统日期
,我需要显示剩余时间意味着假设如果考试时间是 10 分钟,那么它必须
以相反的方式显示时间。或者我需要使用另一个时钟。任何帮助表示赞赏。

4

2 回答 2

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.

}
}
于 2012-04-11T08:47:32.343 回答
0

看看CountDownTimer-class。

于 2012-04-11T08:40:25.233 回答