eyal
eyal

Reputation: 2409

Android How To create RadioButtons like a row of Buttons

In My app i have a search option for stores. I can do the search with two criteria: By Name and By Distance. The user can choose only one of them. The required "shape" is Search layout

The required RadioButtons marked by the red "circle". How it can be done? Thanks, Eyal.

Upvotes: 0

Views: 99

Answers (2)

Top Cat
Top Cat

Reputation: 2483

Use ToggleButtons

<ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toggle"
        android:id="@+id/toggleButton"/>

Upvotes: 0

AnswerBot
AnswerBot

Reputation: 447

You can change your radiobutton in xml to something like this

<RadioButton
 android:id="@+id/radio0"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background="@drawable/customradiobutton"
 android:button="@android:color/transparent"
 android:checked="true"
 android:text="RadioButton1" />

And for customradiobutton you can add

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:drawable="@drawable/checked_image"
    android:state_checked="true" />
<item
    android:drawable="@drawable/unchecked_image" />

Another better idea would to use ToggleButton instead of RadioButtons

Upvotes: 1

Related Questions