title: Can this be done: Variable number of radio buttons in a radio group inside a table?
body: <p>I currently have code that creates rows in a table that hold a string in column 1 with a RadioButton in column 2. </p>
  
  <p>There can be a variable number of these rows. That all works just great, but I want to add them to a RadioGroup so only one button can be toggled at a time.</p>
  
  <p>When I tried to add the dynamic RadioButton to the RadioGroup AFTER I added it to the table row, I got an error saying that the child (the RadioButton) already had a parent. I agree, it does have one, the TableRow.</p>
  
  <p>My question is, can you have radio buttons tied to a radio group inside of a row or, should I just code my own toggle mechanism and avoid RadioGroup all together? I mean, I could code the onClick to unclick all other radio buttons, but I would rather not do this if I can use the build in RadioGroup.</p>
  
  <p>Here is the layout:</p>
  
  <pre><code>                &lt;ScrollView
                      android:id="@+id/ScrollViewModifyGroups"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:scrollbars="vertical"&gt;
                      &lt;TableLayout
                          android:id="@+id/TableLayout_ModifyGroups"
                          android:layout_width="fill_parent"
                          android:layout_height="fill_parent"
                          android:stretchColumns="*"&gt;
                          &lt;TableRow&gt;
                              &lt;RadioGroup
                                  android:id="@+id/radiogroup"
                                  android:layout_width="fill_parent"
                                  android:layout_height="wrap_content"
                                  android:orientation="vertical"&gt;
                               &lt;/RadioGroup&gt;
                          &lt;/TableRow&gt;
  
                      &lt;/TableLayout&gt;
                  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Here is the Java code snippet of what I am doing:</p>
  
  <pre><code>  TableLayout modifyGroupTable = (TableLayout)findViewById(R.id.TableLayout_ModifyGroups);
  
    RadioButton groupButton = new RadioButton(this);
  
    insertGroupRow(modifyGroupTable, "SOME ID", groupButton);
  
  
  
  
      private void insertGroupRow(final TableLayout groupTable, String groupName, RadioButton radioButton)
      {
          final TableRow newRow = new TableRow(ReplayerCreateGroupsActivity.this);
  
          int textColor = getResources().getColor(R.color.title_color);
          float textSize = getResources().getDimension(R.dimen.help_text_size);
  
          addTextToRowWithValues(newRow, groupName, textColor, textSize);
  
          newRow.addView(radioButton);         
  
          groupTable.addView(newRow);
  
          try
          {
           radioGroup.addView(radioButton);
          }
          catch(Exception e)
          {
           e.printStackTrace();
  
          }
      }
  </code></pre>