Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set HH:MM:SS of Chronometer

I knew the format of chronometer can be MM:SS or HH:MM:SS, but I want to know how to use setFormat() and getFormat() to set HH:MM:SS pattern(now is MM:SS).

At this time, I use: android:format="@string/chronometer_initial_format" to set Format by declare:

<xliff:g id="initial-format">%1$s</xliff:g>

at res/values/strings.xml

I tried to search by googling, but can't get good answer. Anyone can suggest ? Thank you

like image 320
Yoo Avatar asked Jun 22 '11 08:06

Yoo


1 Answers

From http://developer.android.com/reference/android/widget/Chronometer.html#setFormat%28java.lang.String%29:

Sets the format string used for display. The Chronometer will display this string, with the first "%s" replaced by the current timer value in "MM:SS" or "H:MM:SS" form. If the format string is null, or if you never call setFormat(), the Chronometer will simply display the timer value in "MM:SS" or "H:MM:SS" form.

The display of the H:MM:SS output depends on the elapsed time: you can not explicitly choose to display the hours. If it has been more than an hour since it started then it will display the hour number, otherwise it will only display the minutes and seconds.

Also, your format must only have %s: I don't believe you can use %1$s or other indexed format specifiers.

like image 55
Femi Avatar answered Oct 18 '22 14:10

Femi