not working if added runtime
I need to add custom views to the radio group it seems working when added on layout. But its not working when added dynamically.
Same for me. If I use RadioGroupPlus.addView(...) to add a LinearLayout which contains a RadioButton, only the 1st LinearLayout (together with its radio button) is displayed. So this piece of solution is incomplete.
It turns out to be an Android SDK bug in LinearLayout which the RadioGroupPlus class extends. LinearLayout has an attribute called orientation that can be either VERTICAL or HORIZONTAL. By right, it can be set either in XML or source code: In XML:
<com.moht.hopes.survey.RadioGroupPlus
android:id="@+id/radioGroupPlus"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:paddingTop="10dp"
android:paddingBottom="50dp" />
In source code,
public RadioGroupPlus(Context context) {
super(context);
setOrientation(VERTICAL);
init();
}
However, it turns out that this orientation can only be set effectively in XML, if you don't set it in XML, if will default to HORIZONTAL. Later, even if you set it to VERTICAL in the source code, it will still be horizontal and thus, only the 1st item is shown.