I've installed a radiogroup with three radio buttons on my app, but I want text to apear above it like it does with checkboxes and such. Can I reference the strings.xml file like this?
<RadioGroup
android:id="@+id/set_radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/between_games_timer"
android:orientation="vertical"
android:text="@string/sets_radio_group" >
<RadioButton
android:id="@+id/one_set"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton
android:id="@+id/two_sets"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton
android:id="@+id/three_sets"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
Because when I run the app the three radio buttons appear without any text. Or is there an easier way?
Old question, but maybe my answer will help somebody.
One of the ways to add a header for all buttons, is to simply use TextView
inside RadioGroup
.
And of course, you can set text for each radio button.
You should use android:text
property to set text for each of buttons. I used usual strings in examples below, but you should better extract your strings into Strings.xml
Here is an example:
<RadioGroup
android:id="@+id/set_radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose one of three types:"
/>
<RadioButton
android:id="@+id/onse_set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type one"
/>
<RadioButton
android:id="@+id/two_sets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type two"
/>
<RadioButton
android:id="@+id/three_sets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type three"
/>
</RadioGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With