Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Chronometer format

Tags:

android

How can I set Android Chronometer format to HH:MM:SS??

like image 657
Altaf Avatar asked Feb 04 '11 11:02

Altaf


People also ask

How do I change the chronometer format?

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.

How to set time in Chronometer in android?

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.

How to use Chronometer in android?

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.


1 Answers

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));
    }
});
like image 106
Stéphane Avatar answered Sep 27 '22 17:09

Stéphane