Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun main() {
val buttonWithSingleClickButton = Button()
buttonWithSingleClickButton.setOnClickListener {
println("buttonWithSingleClickButton clicked")
operation()
}
buttonWithSingleClickButton.click() // Output: Operation Executed
var clickCounter = 0
val times = 3
val buttonWithMultipleClicksButton = Button()
buttonWithMultipleClicksButton.setOnClickListener {
println("buttonWithMultipleClicksButton clicked")
clickCounter++
if (clickCounter == times) {
clickCounter = 0 // reset click counter
operation()
}
}
buttonWithMultipleClicksButton.click()
buttonWithMultipleClicksButton.click()
buttonWithMultipleClicksButton.click() // Output: Operation Executed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment