Set HH:MM:SS of Chronometer

喜你入骨 提交于 2019-12-23 12:57:19

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6437126/set-hhmmss-of-chronometer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!