カウントダウンするタイマーがあります。表示形式を00.00または「ss.SS」にしたい。しかし、私は何時間も進歩していません。SimpleDateFormat がないと、01.91 と表示されてから 01.9 になります。これにより、ビューを中央に保つためにちらつくため、見るのが難しくなります。私が本当に望んでいるのは、フォーマット 01.90 を維持し、0 を削除できないようにする方法だけです。SimpleDateFormat を使用せずに、元のコードでこれを達成できますか?
/*
* This is my original code before I tried the SimpleDateFormat
*
* This code is fully functional and works good, it just keeps dropping the 0 every
* 10 milliseconds and makes the view shake
*
* getTimeSecs() could return 5, 10, 15, 30, 90 seconds converted to milliseconds
* getCountDownInterval() returns 10
*
*/
public void createTimer() {
myCounter = new CountDownTimer(getTimeSecs(), getCountDownInterval()) {
public void onTick(long millisUntilFinished) {
timerIsRunning = true;
if(millisUntilFinished < 10000) {
TVcountDown.setText("0" + ((millisUntilFinished / 10) / 100.0));
} else {
TVcountDown.setText("" + ((millisUntilFinished / 10) / 100.0));
}
} //end onTick()
@Override
public void onFinish() {
timerIsRunning = false;
TVcountDown.setBackgroundColor(myRes.getColor(R.color.solid_red));
TVcountDown.setTextColor(myRes.getColor(R.color.white));
TVcountDown.setText("Expired");
// Make sure vibrate feature is enabled
if(wantsVib == true) {
vib.vibrate(300);
}
} //end onFinish()
}.start();
} //end createTimer()
SimpleDateFormat を試した後のコードは次のとおりです
public void createTimer() {
myCounter = new CountDownTimer(getTimeSecs(), getCountDownInterval()) {
public void onTick(long millisUntilFinished) {
timerIsRunning = true;
long current = (long) ((millisUntilFinished / 10) / 100.0);
TVcountDown.setText("" + timerDisplay.format(current));
}
@Override
public void onFinish() {
timerIsRunning = false;
TVcountDown.setBackgroundColor(myRes.getColor(R.color.solid_red));
TVcountDown.setTextColor(myRes.getColor(R.color.white));
TVcountDown.setText("Expired");
// Make sure vibrate feature is enabled
if(wantsVib == true) {
vib.vibrate(300);
}
}
}.start();
} //end createTimer()
知っている!私は SimpleDateFormat でそれを手に入れることに近づいているとは思いませんし、イライラしています。実行されますが、ミリ秒側で秒だけカウントダウンします。したがって、15 秒は 15.00 ではなく 00.15 を示します。
誰かが私のためにそれをすべてコーディングすることは期待していません。正しい方向に向けるだけです。私が見つけることができるすべてのチュートリアルには、何年も何日もかかるものがありますが、そこから概念を理解することはできません.
私は SimpleDateFormat を使用しないことを好みます-私にとっては単純ではありませんでした-元のコードを使用して、10ミリ秒ごとにミリ秒側の末尾にゼロを追加します。
前もって感謝します。