0

I've a RadioGroup inside a ConstraintLayout. I've a list of Radio buttons (those are comming from remote server call). So the number of radio buttons is not fixed. Sometimes it can be 5, sometimes 10 or any size. I've to show those radio buttons column-wise, like below image.

Mockup for radio buttons

I've follow this thread to add radio buttons dynamically. I can show radio buttons horizontally or vertically. To show horizontal I used this code:

healthCheckRadioGroup.setOrientation(LinearLayout.HORIZONTAL);

for(String healthPlan: healthCheckPlanList){
    RadioButton radioButton = new RadioButton(getContext());
    radioButton.setId(View.generateViewId());
    radioButton.setText(healthPlan);

    healthCheckRadioGroup.addView(radioButton);
}

Result of above code is, a single horizontal list of radio buttons. and most of the buttons are out of the parent layout (I mean invisible)

Please help me to obtain the output. Thanks.

Community
  • 1
  • 1
Hasan Abdullah
  • 2,498
  • 1
  • 19
  • 34

1 Answers1

0

After a long time search, I found this library to achieve my requirement. I can set number of column here. Simply added this line:

healthCheckRadioGroup.setMaxInRow(4);

And the remaining part of code as like as before.

If anyone can suggest for a better solution, you are most welcome.

Hasan Abdullah
  • 2,498
  • 1
  • 19
  • 34