I'm making a race timing app in Android Studio in kotlin that calculates a bunch of useful information off of split times. At the beginning of the race, bib 1 starts at 0, but bib 2 might start 15s later. I want the user to see each racer in a RecyclerView with a chronometer counting up (from for example -15) until that racer's start (0), and continue counting up as the race is going. What I've noticed is the Chronometer widget counts zero twice when it is starting from negative numbers and goes into positive numbers. Is there a way to have it only count zero once?
Below is code to set the chronometer inside of each cardview to the time until they start, and then starting them.
p0.athleteChrono.base = (SystemClock.elapsedRealtime() + racer.startTime *1000)
p0.athleteChrono.start()
Again, it sets itself correctly to, for example -00:10, starts counting up, but definitely displays -00:01, 00:00, 00:00, 00:01 before continuing up
Here is a sample main activity that just has a chronometer set to -3
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnStart.setOnClickListener {
chronometer.base = SystemClock.elapsedRealtime() + 3000
chronometer.start()
}
}
}
and the sample layout file activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/chronometer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Chronometer"></TextView>
<Chronometer
android:id="@+id/chronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="10dp"></Chronometer>
<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/chronometer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/colorPrimary"
android:text="Start"></Button>
</androidx.constraintlayout.widget.ConstraintLayout>