How can I set Android Chronometer format to HH:MM:SS??
By default it will display the current timer value in the form "MM:SS" or "H:MM:SS", or you can use setFormat(String) to format the timer value into an arbitrary string. This works, but it is more efficient to work with the time as a long rather than instantiating a new Date and DateFormat object every second.
setBase(long base): set base function of chronometer is used to set the time that count up time is in reference to. You can give it a start time in the elapsedRealtime() timebase, and it counts up from that, or if you don't give it a base time, it will use the time at which you call start(). SystemClock.
Chronometer is a widget in android which is used to display a timer-like view in the android application. We can use it like a timer where we can provide an up and down time counter. In this article, we will look at how to use Chronometer in an android application.
first proposal - left only for history
Chronometer c;
...
c.setFormat("HH:MM:SS");
see http://developer.android.com/reference/android/widget/Chronometer.html#setFormat%28java.lang.String%29
Edit - This does not work at all! Sorry for the too fast, untested answer... Here is something that works:
Chronometer c;
...
c.setOnChronometerTickListener(new OnChronometerTickListener() {
public void onChronometerTick(Chronometer cArg) {
long t = SystemClock.elapsedRealtime() - cArg.getBase();
cArg.setText(DateFormat.format("kk:mm:ss", t));
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With