Problem With Stopwatch In Android
in my app i have placed a stop watch with two buttons. The stop watch works in a proper way. But the problem is at start the timer looks as 0:0:0, when it starts counting the singl
Solution 1:
This should do the work:
String time = String.format("%02d:%02d:%02d", hr, min, sec);
stopWatch.setText(time);
Or the one-line-version:
stopWatch.setText(String.format("%02d:%02d:%02d", hr, min, sec));
Solution 2:
set the text like so
stopWatch.setText(""+(hr<10?"0"+hr:hr)+":"+(min<10?"0"+min:min)+":"+(sec<10?"0"+sec:sec));
Solution 3:
will:
stopWatch.setText("00:00:00");
not do the trick when you initialise it?
Solution 4:
It's simple you just add this code
private Handler threadHandler = new Handler()
{
public void handleMessage(android.os.Message msg)
{
sec=time2++;
if(sec == 59)
{
time2=0;
sec = time2++;
min=time1++;
if(sec< 10)
sec= "0"+sec
}
if(min == 59)
{
time1=0;
min = time1++;
hr=time3++;
if(min< 10)
min= "0"+min
}
if(hr< 10)
hr= "0"+hr
stopWatch.setText(""+hr+":"+min+":"+sec);
}
};
Post a Comment for "Problem With Stopwatch In Android"