Professional Documents
Culture Documents
Android - Creating RadioGroup Programmatically - Stack Overflow
Android - Creating RadioGroup Programmatically - Stack Overflow
Android - Creating RadioGroup Programmatically - Stack Overflow
Each month, over 50 million developers come to Stack Overflow to Google Facebook
learn, share their knowledge, and build their careers. OR
Error:The specified child already has a parent you must call removeView on the child's
parent first
My logcat shows:
android
and layout which u set for radiogroup that will outside the loop, because radiogroup layout set one time now
u add ur buttons in group, so no need to add radiogroup in loop – Rohit Nov 12 '13 at 12:39
4 Answers
this The specified child already has a parent. You must call removeView() on the child's parent
first. because you are adding child( radio group ) to the parent layout multiple times.
why do you have rg.addView(rb[i]) before setting text and id? also you are adding view to rg again at the
end – Bhargav Oct 1 '15 at 8:03
yes. that will work... and adding RadioGroup at the end to the parent Layout. – RajaReddy PolamReddy Oct
1 '15 at 8:11
For me, it worked only after removing "rg.addView(radiobutton[i]);" – Ashish John Dec 28 '15 at 11:11
I am also trying this solution but using this way radio group allowing me to select all radio button inside it. It
should be only single selection of radio button within the same radio group. – Min2 Mar 15 '16 at 7:31
<string-array name="some_array">
<item>some_item_0</item>
<item>some_item_1</item>
<item>some_item_2</item>
</string-array>
I don't think you need id but text for each button so put somewhere this method (in my case
this is Utils class):
if(radioGroup.getChildCount() > 0)
radioGroup.check(radioGroup.getChildAt(0).getId());
}
if(radioGroup.getChildCount() > 0)
String text = ((RadioButton)
findViewById(radioGroup.getCheckedRadioButtonId())).getText().toString();
<string-array name="websites_array">
<item>Yahoo</item>
<item>Hotmail</item>
<item>Gmail</item>
<item>Facebook</item>
<item>Other</item>
</string-array>
try this