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.
Enable with a Handler like this after 1500 ms.
mTrueButton.setEnabled(false);
mFalseButton.setEnabled(false);
checkAnswer(false); //Display the appropriate Toast
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mTrueButton.setEnabled(true);
mFalseButton.setEnabled(true);
}
}, 1500);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With