I am trying to add radio buttons to radio groups with table layout when I started the code I am getting some error. Here is my code
RadioButton[] boxes = new RadioButton[30];
RadioGroup rg = (RadioGroup) findViewById(R.id.radiogroup);
for (int i = 0; i < 30; i++) {
boxes[i] = (RadioButton) findViewById(idArray[i]);
}
for (int i = 0; i < 30; i++) {
rg.addView(boxes[i]);
}
Xml code is here`
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11-12(T1)"
android:id="@+id/radioButton0"
android:layout_column="9"
android:checked="false" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11-12(T2)"
android:id="@+id/radioButton10"
android:checked="false"
android:layout_marginLeft="40dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11-12(T3)"
android:id="@+id/radioButton20"
android:layout_column="11"
android:checked="false"
android:layout_marginLeft="40dp" />
</TableRow>
</TableLayout>
</RadioGroup>
I didnt post whole xml code because there are 10 table row like that each table row has 3 radio butttons so ı have 30 radio button in 3*10 grid. In java code ı get error like that " The specified child already has a parent. You must call removeView() on the child's parent first."
add the radio buttons to a RadioGroup and then the RadioGroup to the layout. And finally use this to show!