Question

I am adding a radio group with radio buttons to my view like this:

RadioGroup control =  new RadioGroup( this.getActivity() );
String[] items = content.getDesc().split(",");
control.setOrientation(RadioGroup.HORIZONTAL);
control.setLayoutParams(new LayoutParams(
    LayoutParams.MATCH_PARENT,
    LayoutParams.WRAP_CONTENT));
for(int i = 0; i < items.length; i++){
    RadioButton rBtn  = new RadioButton( this.getActivity() );
    rBtn.setId(i);
    rBtn.setChecked(true);
    rBtn.setText(items[i]);
    control.addView(rBtn); 
}
control.setTag(content.getId());
controlList.add(control);
layout.addView(control); //layout is a linear layout

However, for some values of i (2 on my phone), the radio buttons start appearing off the screen. Is there a way to set it so that they automatically overflow to the next line if they are off the screen?

Was it helpful?

Solution

As far as I am aware, a radiogroup can only exist in a single line. If you are having trouble with the items overflowing from your screen, I would recommend either using a vertical group, or a spinner instead.

OTHER TIPS

You are setting the orientation to horizontal. At some point you will run out of horizontal space on screen, so the horizontal RadioGroup will have children that are outside the bounds of the screen. Unless you wrap that in a HorizontalScrollView, those will not be visible.

You may be better off letting it be vertical, or find some other way to present this control to the user (like a Spinner).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top