In the code, there is a variable running
, which indicates whether the timer is running or not:
boolean running = false;
And there is a StartStopTimer
method, which stops or starts the timer according to the variable:
public void startStopTimer(View v){
Chronometer chr = (Chronometer) findViewById(R.id.chronometer);
Button ahj = (Button) findViewById(R.id.button4);
if(running == false){
chr.start();
running = true;
ahj.setText("Stop Timer");
}
else if(running == true){
chr.stop();
ahj.setText("Start Timer");
running = false;
}
}
Only, when I run the application, the timer does not start from scratch. If the application has been running for 15 seconds, for example, it starts at 15 seconds. How do you get it started from 0?
Timer properties:
<Chronometer
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chronometer"
android:textSize="100dp"
android:layout_alignTop="@+id/valor1"
android:layout_centerHorizontal="true" />
Thank you in advance: D