Omar
Omar

Reputation: 8145

Using RadioGroup and RadioButtons

Hey, I want to make the Text of a RadioButton appear on the left side of the RadioButton.. so I tried using 2 relative views (I have 2 RadioButtons) and it worked but the problem is in RadioGroup not working properly.. Heres the code:

<RelativeLayout android:id="@+id/SearchRelative" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">

    <RadioButton android:checked="true" 
        android:id="@+id/SearchRadioButtonAloneWord" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true">
    </RadioButton>

    <TextView android:text="1" 
        android:layout_toLeftOf="@+id/SearchRadioButtonAloneWord"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
</RelativeLayout>

<RelativeLayout android:id="@+id/SearchRelative" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">

    <RadioButton android:id="@+id/SearchRadioButtonInBetweenWord"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true">
    </RadioButton>

    <TextView android:text="2"
        android:layout_toLeftOf="@+id/SearchRadioButtonInBetweenWord"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </TextView>
</RelativeLayout>

They get displayed properly with the text on the left side of its RadioButton.. but the RadioGroup doesnt work!
How can I fix this?
Thanks

Edit1: is it possible to dynamically add RadioButtons to a group? thats one way of fixing my problem!

Upvotes: 3

Views: 1097

Answers (1)

Malcolm
Malcolm

Reputation: 41510

Regarding using layout managers inside a RadioGroup: sorry, it doesn't work that way. As far as I know, if something is added to a RadioGroup which is not an instance of RadioButton, it is not managed by this RadioGroup. But this presents an alterntive solution to the problem: extending RadioButton to draw it the way you want.

As for dynamic manipulation: yes, this is possible with RadioGroup just like with any other ViewGroup. All you have to do is to add RadioButtons via RadioGroup.addView().

Upvotes: 4

Related Questions