Disable button when clicked, then re-enable it

Viewed 1959

I am starting out Android development by building a simple quiz app with only two buttons, True and False. The app displays a Toast saying whether the answer is correct or incorrect.
What I am trying to do is disable both the buttons as soon as either is clicked/tapped, then re-enable them after the Toast has been displayed. This is what I tried in my listener for the buttons:

mFalseButton.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v){
            mTrueButton.setEnabled(false);
            mFalseButton.setEnabled(false);

            checkAnswer(false); //Display the appropriate Toast

            mTrueButton.setEnabled(true);
            mFalseButton.setEnabled(true);
        }
    });

This does not work. My buttons never get disabled when they are clicked/tapped. How can I do this correctly? Any help would be highly appreciated.

5 Answers
Related