• ANDROID: How to put a delay after a button is pushed?

    In your onClickListener for the button:
    myButton.setEnabled(false);
    
    Timer buttonTimer = new Timer();
    buttonTimer.schedule(new TimerTask() {
    
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
    
                @Override
                public void run() {
                    myButton.setEnabled(true);
                }
            });
        }
    }, 5000);
    This will disable the button when clicked, and enable it again after 5 seconds.
    If the click event is handled in class that extends View rather than in an Activity do the same thing but replace runOnUiThread with post.
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari