By default, the value is displayed in "MM: SS" format, changing to "H: MM: SS" when the minute is greater than 59.
The Chronometer class provides the serFormat () However, contrary to what your name may suggest, it is not meant to change this standard.
It serves to compose a string, to be displayed, where a first occurrence of "% s" is replaced by the current stopwatch value, in the form "MM: SS" or "H: MM: SS".
For example, using chronometer.setFormat("Passaram %s desde o início");
will result in
-
if the value is less than 60 seconds:
Passaram 48:55 desde o início
-
if the value is greater than 59 seconds:
Passaram 1:25:23 desde o início
If there is no method in the class that does this directly, you can do it indirectly using a OnChronometerTickListener
and in the onChronometerTick()
method, take the current value, format it as you want, and assign it to the text of the Chronometer.
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
long time = SystemClock.elapsedRealtime() - chronometer.getBase();
String minSec = String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
);
chronometer.setText(minSec);
}
});