To disable a button, it is done using the android:enabled
property where the boolean value determines if the view is enabled or disabled:
The default of the view is android:enabled="true"
whereby the view is enabled:
<Button
android:text="Boton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:enabled="true"/>
can be done programmatically by:
Button boton = (Button) findViewById(R.id.button);
boton.setEnabled(true); //Asigna valor true.
Disable button:
To disable a button is done using the property android:enabled="false"
<Button
android:text="Boton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:enabled="true"/>
can be done programmatically by:
Button boton = (Button) findViewById(R.id.button);
boton.setEnabled(false); //Asigna valor false.
In the case that you comment, add two buttons in your layout:
and using a onClickListener
change enable / disable the button:
final Button botonA = (Button) findViewById(R.id.buttonA);
final Button botonB = (Button) findViewById(R.id.buttonB);
botonA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
botonB.setEnabled(false);
}
});
botonB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
botonA.setEnabled(false);
}
});
For what you need is to choose a button and disable others I think it would be better to use a RadioGroup containing several RadioButton
where selecting only one element would be enabled.