0

I am generating a radiogroup dynamically. Then I add some radio buttons dynamically to this group.

Now my Problem is, that I want to split the text of the radiobutton, that one part is directly on the left of the rbutton and the other part on the right side of the screen. I want to do it like this example with checkboxes:

enter image description here

My Code looks like this:

LinearLayout allOptionsLayout = new LinearLayout(ItemConfigActivity.this);
allOptionsLayout.setOrientation(LinearLayout.VERTICAL);
configLayout.addView(allOptionsLayout);

List<RadioGroup> rGroups = new ArrayList<>();

for (int i = 0; i < configOptions.length; i++) {

    LinearLayout optionLayout = new LinearLayout(ItemConfigActivity.this);
    optionLayout.setOrientation(LinearLayout.HORIZONTAL);
    allOptionsLayout.addView(optionLayout);

    if (i == 0) {
        RadioGroup rGroup = new RadioGroup(ItemConfigActivity.this);
        rGroups.add(rGroup);
        optionLayout.addView(rGroup);
    }

    final RadioButton rButton = new RadioButton(ItemConfigActivity.this);
    rButton.setText(price + "€");
    rGroups.get(rGroups.size() - 1).addView(rButton);

    // here doing some rbutton setonclicklistener and other irrelevant stuff
}

What I tried: I tried to set a LinearLayout and add the radiobutton and two TextViews to this layout. Then add this Layout to the radioGroup. The Problem is, that if I do so, the radiogroup doesn't work properly anymore. I can click on as many radiobuttons as I want and they don't get unchecked automatically anymore. So I am wondering what is the best practice to do something like this?

progNewbie
  • 4,362
  • 9
  • 48
  • 107

0 Answers0