Good afternoon, I was trying and I don't understand how to do it. I want the user to choose an option, pressing a button, depending on which button he has chosen passes a certain action. The problem is that if I press button A I want button B to be disabled and vice versa I can't do it. Can someone give me an idea how to do it? Thank you
To disable a button is done through the property
android:enabled
where the boolean value determines if the view is enabled or disabled:The view's default is
android:enabled="true"
why the view is enabled:programmatically it can be done by:
Disable button:
To disable a button is done through the property
android:enabled="false"
programmatically it can be done by:
In the case you mention, add two buttons in your layout:
and by means of a
onClickListener
switch enables/disables the button:For what you need, which is to choose a button and disable the others, I think it would be better to use a RadioGroup containing several
RadioButton
where when selecting only one element it would be enabled.interesting your question, you can try with this code:
When you want to enable the same button just write
Knowing that, I think it's just messing with the If and else between the two buttons.
I hope I've helped!
Something like that?
Visually I would recommend using a CheckButton https://github.com/navasmdc/MaterialDesignLibrary#checkbox https://github.com/rey5137/material