How do I make a button unclickable for a period of time?
How do I make a button unclickable for a period of ti开发者_如何学编程me?
Ask for more information if needed.
This is on android.
if you want unclickable Button then you can use Button.setEnabled(false);
You can use TimerTask
which runs at a specified time repeaditly or once. Please refer Updating the UI from a Timer document.
Untested Code
You can use a handler
. The given code make your button unclickable for 1.5 seconds. and then re enable it.
int Delay = 1500; //1.5 seconds
yourView.setEnabled(false);// for making the button grey and unclickable
new Handler().postDelayed(new Runnable()
{
public void run()
{
yourView.setEnabled(true);
}
},Delay);
Second Method
//initiate the button
button.setEnabled(true);
button.invalidate();
// delay completion till animation completes
button.postDelayed(new Runnable() { //delay button
public void run() {
button.setEnabled(false);
button.invalidate();
//any other associated action
}
}, 800); // .8secs delay time
You can first disable your button with setEnabled(false)
and use postDelayed to enable it again after a specific period of time
An interesting thing you could do is use an ObjectAnimator
and animate an int value from 0 to 1. I'll try this later.
精彩评论