この質問は混乱を招く可能性があるため、以下で説明します。
私はすでに時間をカウントするためのカウンターを作成しています(人々が働いている時間など)。単一の文字(0:0:0など)で正常に機能しますが、10進数(00:00:00など)で表示したい. 以下のコードを試してみましたが、以前と同じように動作します。まだ変更はありません。
private void timer() {
int locSec = 0;
int locMin = 0;
int locHr = 0;
DecimalFormat format = new DecimalFormat("00");
String formatSecond = format.format(locSec);
String formatMinute = format.format(locMin);
String formatHour = format.format(locHr);
sec = Integer.parseInt(formatSecond);
min = Integer.parseInt(formatMinute);
hr = Integer.parseInt(formatHour);
Timer T = new Timer();
timeCounter = (TextView) findViewById(R.id.tvDisplayCountDown);
T.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
timeCounter.setText("time= " + hr + ":"+ min + ":"+ sec);
sec++;
if(sec > 59){
sec = 0;
min = min + 1;
}
}
});
}
}, 1000, 1000);
}
ここで、hr、min、secglobal variables and assigned as 0.
はoutput is same as before: 0:0:0
ヘルプと提案はかなりのものです。
ありがとうございました