Search code examples
androidchronometer

Chronometer doesn't overwrite base value


When I call chronometer.start(), the chronometer starts counting but the base value (00:00) is still there and it is not overwritten.

chronometer in my xml file looks like this

<Chronometer
 android:id="@+id/chronometer"
 android:layout_width="100dp"
 android:layout_height="50dp"/>

and code in my Activity looks like this

 chronometer.setBase(SystemClock.elapsedRealtime());
 chronometer.start();

and the result looks like this

chronometer

Did anyone face the same problem ?


Solution

  • Only thing you need to do is to initialize chronometr first:

    chronometer = view.findViewById(R.id.chronometer); chronometer.setText("");

    and then you can start your chronometr without overwriting

    chronometer.start();