简体   繁体   中英

Android disabling a button

I can't figure out why this wouldn't set a button to be disabled?

btnSaturdayStartTime = (Button)findViewById(R.id.btnSaturdayStartTime);
btnSaturdayStartTime.setEnabled(false);     

When I click on the button it still fires the listener.

Try using btnSaturdayStartTime.setClickable(false).

See setClickable from the docs.

try the method: Button.setClickable(false); or delete the listener on your button like this: button.setOnClickListener(null);

Maybe the button is recreated or re-enabled between you disabling it an the user click interaction. Are you sure you are disabling the right button? What version of Android are you targeting?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM