Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a radio group to radio buttons inside of a table?

Tags:

android

xml

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.

like image 518
Fizz Avatar asked Mar 02 '10 06:03

Fizz


People also ask

How do I group radio buttons in a table?

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.

How do I group set radio buttons?

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.

How do I add a radio button to a radio group dynamically?

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.

How do I add a radio group?

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.


1 Answers

Your RadioButton widgets must be immediate children of the RadioGroup for the group effect to work.

like image 70
CommonsWare Avatar answered Oct 19 '22 16:10

CommonsWare