gpt4 book ai didi

android - 如何在数字时钟中显示剩余时间?

转载 作者:行者123 更新时间:2023-11-30 04:15:29 25 4
gpt4 key购买 nike

正在为学生创建一个应用程序。我需要显示剩余时间的数字时钟。
我在这里添加数字时钟
enter image description here
但它显示系统日期
我需要显示剩余时间意味着如果考试时间是 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.

}
}

关于android - 如何在数字时钟中显示剩余时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10102358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com