I currently have code that creates rows in a table that hold a string in column 1 with a RadioButton in column 2.
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.
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.
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.
Here is the layout:
<ScrollView
android:id="@+id/ScrollViewModifyGroups"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<TableLayout
android:id="@+id/TableLayout_ModifyGroups"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*">
<TableRow>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</RadioGroup>
</TableRow>
</TableLayout>
</ScrollView>
Here is the Java code snippet of what I am doing:
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();
}
}