我有一個CountDown計時器,以10000秒爲單位向下計數,以1秒爲增量遞減,以使按鈕在10秒後可點擊。雖然計時器是準確的,並且做了什麼代碼說,我想改變秒的表達方式,但我不知道如何。讓倒數計時器從10秒變爲1秒
的java:
void startTimer() {
cTimer = new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
c.setText("Please wait " + millisUntilFinished/1000 + " seconds");
thx.setText(millisUntilFinished/1000 + "");
thx.setAlpha(.5f);
thx.setClickable(false);
}
public void onFinish() {
c.setText("done");
thx.setText("ready");
thx.setAlpha(1f);
thx.setClickable(true);
}
};
cTimer.start();
}
輸出(每秒):9, 8, 7, 6, 5, 4, 3, 2, 1, (still 1), ready
期望:(每秒):10, 9, 8, 7, 6, 5, 4, 3, 2, 1, ready
謝謝,
乙
編輯:
我加入基於倒計時,thx.setText(((millisUntilFinished/1000) + 1) + "");
新的輸出:10, 9, 8, 7, 6, 5, 4 ,3 , 2, (Still 2), ready
更緊密......但並不完全。
你能看到什麼'thx。setText(millisUntilFinished +「」);'?沒有除法 – Vyacheslav
9901,8901,7900,6897,5896,4890,3890,2889,1888,(1888),就緒 –
如何實例化開始時間例如, 10000計時器上方,然後打勾,您可以將該值減少1000,然後將該數字除以輸出。這會給你更多的控制和精度。 –