I have 5 simple buttons and I want them to behave like radio buttons, but without the tick box (or whatever they call them). They are aligned in row and I want only one of them to be selected at once, and when a button is selected it must keep its selected style. My layout code looks like this:
<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_margin="0dp"
android:text="@string/mybutton1" />
<Button
android:id="@+id/button2"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:text="@string/mybutton2" />
// and so on
My code:
mybtn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mybtn1.setPressed(true);
}
});
So, I don't know if I can do this on the layout or in the code. Is there any way to make the button stay in selected state (and selected style) when I click on it? Also, is it possible to assign the event to all these buttons?
Thanks!