我到处寻找答案,但找不到适合我情况的答案。我有几个问题,也想知道如何包括毫秒倒计时。我正在尝试获取格式为 00.00(秒.毫秒)的倒数计时器。按钮用于启动计时器。我使用的时间取决于按下的按钮,5、10、15、30 或 90 秒。我只是说它的硬编码为 5000 毫秒,以便现在更简单。
long timeSecs = 5000; // really timeSecs is dynamic but for the sake of simplicity
long countDownInterval = 1000; // this is a static value
TextView TVcountDown = (TextView)findViewById(R.id.TVcountDown);
public void createTimer() {
new CountDownTimer(timeSecs, countDownInterval) {
public void onTick(long millisUntilFinished) {
TVcountDown.setText(millisUntilFinished / 1000); // error here on
//.setText unless I cast to an int, which all values are long so I'm not sure why
}
@Override
public void onFinish() {
TVcountDown.setBackgroundColor(R.color.solid_red); // error here
TVcountDown.setTextColor(R.color.white); // error here
TVcountDown.setText("Expired"); // it will make it here
// It doesn't count down, just goes straight to onFinish() and displays "Expired"
}
}.start();
}
提前致谢。我已经用头撞桌子有一段时间了。