Table of radio buttons created dynamically

Hi everyone,

I'm new to Xamarin and to Android. I'm trying to draw the following layout dynamically (programmatically) (I tried to put an image to show it or to draw the table but I couldn't, sorry....)

Thead Thead 1 Thead 2 Thead3 Thead4
Text1 RadioButton RadioButton RadioButton RadioButton
Text2 RadioButton RadioButton RadioButton RadioButton
Text3 RadioButton RadioButton RadioButton RadioButton

The data (labels, radio buttons id's...) is loaded from the database. I've tried using LinearLayout and GridLayout but I'm not even close to achieve it.
All radio buttons in a row are a Radio Group.
How should I start to achieve this layout? Should I use LinearLayout, GridLayout or neither of them?

Thank you very much


  • FabricioBertaniFabricioBertani USMember ✭✭

    Can you please paste your code to see exactly what did you do?

  • aaleahyaaaleahya Member

    Here's the code with what I tried to do with GridLayout. The result of this is that I don't see any of the radio buttons...

                    var table = new GridLayout(cc);
                    table.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                    table.RowCount = arr.Count();
                    table.ColumnCount = arr[0]["Options"].Count();
                    for (int i = 0; i < arr.Count(); i++)
                        string type = arr[i]["Name"].ToString();
                        if (type == Util.RadioButton)
                   // Create radio group
                            RadioGroup Group = new RadioGroup(cc);
                            Group.Orientation = Orientation.Horizontal;
                            Group.LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent);
                   // Radio group options
                            for (int k = 0; k < arr[i]["Options"].Count(); k++)
                                JToken Option = arr[i]["Options"][k];
                                RadioButton rb = new RadioButton(cc);
                                rb.Id = (int)Option["OptionValue"];
                                rb.SetTextSize(ComplexUnitType.Dip, 25);
                                rb.Gravity = GravityFlags.CenterHorizontal | GravityFlags.Bottom;
                            // Add view to grid layout
                    // Add grid layout
Sign In or Register to comment.