worker8 / RadioGroupPlus

A small tweak version of RadioGroup class in Android to expand it's capability
101 stars 36 forks source link

not working if added runtime #3

Open bb1690 opened 7 years ago

bb1690 commented 7 years ago

I need to add custom views to the radio group it seems working when added on layout. But its not working when added dynamically.

xuancong84 commented 3 years ago

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.

xuancong84 commented 3 years ago

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.