There is no component that does this for you similar to RadioGroup
. You need to do this via code, something like:
...
firstButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeButtonState(true, false, false);
}
});
secondButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeButtonState(false, true, false);
}
});
thirdButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeButtonState(false, false, true);
}
});
...
And to change the status of your Button
:
private void changeButtonState(boolean first, boolean second, boolean third) {
// caso você queira alterar a cor do botao selecionado
if (first) {
firstButton.setColorFilter(R.color.yourColor);
secondButton.setColorFilter(R.color.yourColor2);
thirdButton.setColorFilter(R.color.yourColor2);
} else if (second) {
firstButton.setColorFilter(R.color.yourColor2);
secondButton.setColorFilter(R.color.yourColor);
thirdButton.setColorFilter(R.color.yourColor2);
} else {
firstButton.setColorFilter(R.color.yourColor2);
iBtnRatingMedium.setColorFilter(R.color.yourColor2);
thirdButton.setColorFilter(R.color.yourColor);
}
firstButton.setSelected(first);
secondButton.setSelected(second);
thirdButton.setSelected(third);
}