Disable button after first click… here is a solution to the problem.
Disable button after first click
I’m working on a game that includes two activities.
I have one
static
class ModelGetter:public static int getPoint{int static point++; }
。
When the button is clicked in the first activity, the counter increases
If I press the same button twice, how can I avoid this situation in the same activity, where the counter is not incremented twice, but only once?
Solution
Simple: In onClick
, you need to disable the button:
yourButton.setEnabled(false);
So when you try to tap on it again, nothing happens because the button is now disabled.
The complete code is:
yourButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.setEnabled(false);
increment what you want, or other stuff..
}
});