I am trying to avoid repeated touches, but want a sensitive screen. Using the method advised in this answer:
Android Preventing Double Click On A Button
I have been re-enabling buttons within the program flow, but there are some instances where, I cannot rely on program flow and need to ensure the button is enabled.
I have devised a way to re-enable these button using a countdowntimer
and shown in my code:
button.setOnTouchListener(new View.OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
disableButton(button);
countDwn();
// Do something
return false;
}
});
public void disableButton(Button button) {
button.setEnabled(false);
}
public void enableButton(Button button) {
button.setEnabled(true);
}
public void countDwn() {
CountDownTimer countDownTimer = new CountDownTimer(2000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
enableButton(button);
}
}.start();
}
What I am concerned about, is that this may be a clumsy or ineffective way to go about this. I am wanting advice about this and if anyone has a more elegant suggestion?