In my Application I have a simple image switcher and 2 buttons(Next and Previous) at the bottom of screen to switch images. Also I set animation to image switcher with duration 700. So when i click “Next” button firstly I disable next button, and than set to Clickable with delay with the same duration…because i need animation to be finished.
public void onNextButtonPressed(View view) {
setPreviousAndNextButtonsClickable(false);
setPeviousAndNextButtonsClickableWithDuration();
}
private void setPeviousAndNextButtonsClickableWithDuration() {
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
public void run() {
setPreviousAndNextButtonsClickable(true);
}
}, 700);
}
private void setPreviousAndNextButtonsClickable(boolean clicable) {
nextButton.setClickable(clicable);
previousButton.setClickable(clicable);
}
And now about my problem…When I click next button very faster, some time button can click two times with out delay…Looks like i can click faster than button.setCkickable() method work… What is the problem ? Can it be because of device ? I’m trying that on HTS with android 2.2 where I reproduce a bug…and also on android 2.3.4 where i cannot reproduce that…Is that because device is slow or something wrong in my code ? thanks…
delayMillis The delay (in milliseconds) until the
Runnablewill be executed.Returns
I think your
buttongets enabled in 700 ms and that’s a very small duration and that’s why you are facing this issue.Try increasing the delay and see.