Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable button after first click

Tags:

java

android

I'm making a game, which include two activities.
I have one

static class ModelGetter: public static int getPoint{int static point++;}.

When click a button in the first activity, the counter is incremented How can I avoid that in the same activity if I press twice the same button the counter don't incremente a counter two time, but just one?

like image 977
BarcelonaDev Avatar asked Dec 11 '25 09:12

BarcelonaDev


1 Answers

Simple: inside the onClick, you need to disable the button:

yourButton.setEnabled(false); 

So, when you retry to click it, nothing will happen, since the button is now disabled.

The comple code will be:

yourButton.setOnClickListener(new OnClickListener() {           
            @Override
            public void onClick(View v) {
                v.setEnabled(false);
                // increment what you want, or other stuff..
            }
        });
like image 86
GVillani82 Avatar answered Dec 12 '25 21:12

GVillani82



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!