Hello,
Welcome to our Microsoft Q&A platform!
but I would be adding or removing RadioButtons from a RadioGroup instead of some other layout. Is there any good way to do this, or do I need to do it manually?
I think need to do it manually with background code.
Firstly, we need to add the RadioGroup
in the xml or background code. then add the RadioButtons
at the runtime with background code(based on other factors). Because RadioGroup
do not have adapter like RecyclerView
. I add and remove RadioButton
like following code.
rg = FindViewById<RadioGroup>(Resource.Id.radioGroup1);
Button button1 = FindViewById<Button>(Resource.Id.button1);
rb = new RadioButton[5];
rg.Orientation = Orientation.Horizontal;//or RadioGroup.VERTICAL
for (int i = 0; i < 5; i++)
{
rb[i] = new RadioButton(this);
rg.AddView(rb[i]); //the RadioButtons are added to the radioGroup
rb[i].Text = "Test";
}
//Or remove the RadioButtons
rg.RemoveView(rb[i]);//now the RadioButtons are in the RadioGroup
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.