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

但它会显示系统日期
我需要显示剩余时间意味着假设考试时间是10分钟,那么它必须显示
以相反的方式计时。或者我需要用另一个时钟。任何帮助都是非常感谢的。
发布于 2012-04-11 16:47:32
在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-11 16:40:25
看一看CountDownTimer-class。
https://stackoverflow.com/questions/10102358
复制相似问题