A
A
Albatz2014-11-29 20:22:49
Programming
Albatz, 2014-11-29 20:22:49

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

1 answer(s)
A
Andrey Myvrenik, 2014-11-29
@Albatz

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 question

Ask a Question

731 491 924 answers to any question