so i was trying to mess around with android studio, and decided to make a simple counter app. Every time I press the button(which covers the entire screen) it adds 1, and if i keep the button pressed for 3 sec the counter resets. Simple as that. But unfortunately, can't seem to get the setOnChronometerTickListener to work, and i need it to see when the chronometer reaches 3s. The code I have is here below:
var button = findViewById<Button>(R.id.button)
val chrono = Chronometer(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnTouchListener(OnTouchListener { v , event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> { chronoStart()}
MotionEvent.ACTION_UP -> { chrono.stop()}
}
false
})
}
fun chronoStart() {
chrono.start()
chrono.setOnChronometerTickListener() {}
}
var counter = 0;
fun count(view: View){
val button = view as Button
}
I already tried
chrono.setOnChronometerTickListener(chrono.onChronometerTickListener!!) {}
also tried another code I saw online, but it wasn't up to date. Any ideas on how to solve this problem or even a different way to accomplish the same result?