I have multiple radio buttons which I want to layout using a table but also include them in a single radio group. I have the following xml layout:
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/Group1">
<TableLayout android:id="@+id/RadioButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<RadioButton android:id="@+id/rad1"
android:text="RButton1"
android:layout_width="105px"
android:layout_height="wrap_content"
android:textSize="13px"></RadioButton>
<RadioButton android:id="@+id/rad2"
android:text="RButton2"
android:layout_width="105px"
android:textSize="13px"
android:layout_height="wrap_content"></RadioButton>
<RadioButton android:id="@+id/rad3"
android:text="RButton3"
android:layout_width="105px"
android:textSize="13px"
android:layout_height="wrap_content"></RadioButton>
</TableRow>
</TableLayout>
</RadioGroup>
But unfortunately the radio buttons inside the table seem to ignore the fact that they're inside of the RadioGroup tags and because of this you can select more than one radio button at the time. I noticed that by removing the table and just having the radio buttons it works just fine. How can I overcome this? Would it be as simple as declaring the radio group inside of the table instead of outside? Thanks for any help.
You must set your Label up with the attibute 'for', which matches the ID of the radio button. Even though your input is nested inside the label, you will still need an ID for each. The name attribute can be common. Show activity on this post.
You group radio buttons by drawing them inside a container such as a Panel control, a GroupBox control, or a form. All radio buttons that are added directly to a form become one group. To add separate groups, you must place them inside panels or group boxes.
For creating dynamic RadioButton, we need to use android. view. ViewGroup. LayoutParams which configures the width and height of views and implements setOnCheckedChangeListener() method of RadioGroup class.
For this, open the “MainActivity. java” file and instantiate the components made in the XML file (RadioGroup, TextView, Clear, and Submit Button) using findViewById() method. This method binds the created object to the UI Components with the help of the assigned ID. Button submit = (Button)findViewById(R.
Your RadioButton
widgets must be immediate children of the RadioGroup
for the group effect to work.
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