【发布时间】:2012-04-11 16:47:32
【问题描述】:
我正在为学生创建一个应用程序。我需要显示剩余时间的数字时钟。
我在这里添加数字时钟
但它显示系统日期
我需要显示剩余时间意味着假设如果考试时间是 10 分钟,那么它必须显示
时间以相反的方式。或者我需要使用另一个时钟。
任何帮助表示赞赏。
【问题讨论】:
我正在为学生创建一个应用程序。我需要显示剩余时间的数字时钟。
我在这里添加数字时钟
但它显示系统日期
我需要显示剩余时间意味着假设如果考试时间是 10 分钟,那么它必须显示
时间以相反的方式。或者我需要使用另一个时钟。
任何帮助表示赞赏。
【问题讨论】:
在 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.
}
}
【讨论】:
看看CountDownTimer-class。
【讨论】: