Answer the question
In order to leave comments, you need to log in
How to check the number of clicks on a Button element?
It is necessary to check the number of clicks on the Button element and, after a certain number of clicks, perform an action (for example, display a welcome message).
I'd be grateful for the code snippets.
Answer the question
In order to leave comments, you need to log in
You create a variable for the counter, after each click you increment and check. If the value is greater than n, print a hello message.
private int counter = 0;
public void onButtonClicked() {
counter++;
if(counter >= 3) {
// Приветствие!
counter = 0;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question