Reputation: 2137
I have a RadioGroup in which, I have provided four different radio button with text as :
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="1dp"
android:background="@color/textbackgroundcolor"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:soundEffectsEnabled="true" >
<RadioButton
android:id="@+id/radio_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:checked="false"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="12dp"/>
<RadioButton
android:id="@+id/radio_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:checked="false"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="12dp"/>
<RadioButton
android:id="@+id/radio_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:checked="false"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="12dp"/>
<RadioButton
android:id="@+id/radio_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:checked="false"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="12dp"/>
</RadioGroup>
As of now, it display radio buttons with their text. But I want to display some labels/numbers before each radio button.
How can I provide numbers like 1, 2, 3, 4 for radio button?
Upvotes: 3
Views: 157
Reputation: 1511
There are different ways to do this. But the easiest way that comes to mind is just to add a TextView
before each and place it in a LinearLayout
together with each RadioButten
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="1dp"
android:background="@color/textbackgroundcolor"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:soundEffectsEnabled="true" >
<LinearLayout >
<TextView
android:layout_width="fill_parent"
android:minLines="2"
android:gravity="center"
android:textSize="15dp"
android:text="1"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/radio_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_marginLeft="5dp"
android:checked="false"
android:textStyle="bold"
android:textSize="12dp"/>
</LinearLayout>
</RadioGroup>
This is the general idea
Upvotes: 3