I have a button such as
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="150dp"
android:layout_height="50dp"
android:text="@string/lightning"
android:textColor="#FFFFFF"
android:textSize="14sp"
app:icon="@drawable/ic_baseline_flash_on_24"
app:iconTint="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.061"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.239"
app:strokeColor="@color/white"
app:strokeWidth="1dp" />
I have created a setOnClickListener method and inside their is a loop.
val btnClickMe1 = findViewById<Button>(R.id.button)
btnClickMe1.setOnClickListener {
//do something here 20 times
}
This method works fine, however, I have created a .apk file. When I click the button the function runs. I want to know how I can exit the loop by clicking the same button. Regardless of whether or not the loop has finished.