Android的倒数计时器显示毫秒? [英] Android countdown timer display milliseconds?
本文介绍了Android的倒数计时器显示毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个计时器弹出,当我点击一个按钮,从3秒倒计时。它确实是不错,但我希望它也显示毫秒,所以当我点击按钮上的文字会去从3.0到0.1。如何将我的毫秒添加到文本看法?
I want a timer to pop up when I click a button that will count down from 3 seconds. And it does that fine but i want it to also show the milliseconds so when I click the button the text would go from 3.0 to 0.1. How would I add the milliseconds to the text view?
new CountDownTimer(1000, 3000) {
public void onTick(long millisUntilFinished) {
textViewTimer.setText("" + millisUntilFinished / 1000);
}
public void onFinish() {
textViewTimer.setVisibility(View.INVISIBLE);
textViewLevelGained.setVisibility(View.INVISIBLE);
}
}.start();
这是我所
推荐答案
其他SO问题,建议CountDownTimer没有做分1秒粒度好。寻找到一个不同的类,像TimerTask的。
Other SO questions suggest CountDownTimer doesn't do sub 1-second granularity well. Look into a different class, like TimerTask.
另外,以下是可行的。
new CountDownTimer(3000, 1) {
public void onTick(long millisUntilFinished) {
textViewTimer.setText("" + millisUntilFinished / 1000
+ "." + millisUntilFinished % 1000);
}
public void onFinish() {
textViewTimer.setVisibility(View.INVISIBLE);
textViewLevelGained.setVisibility(View.INVISIBLE);
}
}.start();
这篇关于Android的倒数计时器显示毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文