setChecked 在单选按钮 android 上不起作用?

setChecked not working on radio button android?

我用radioRealButton做了这样的东西

一切正常,如上图所示,我可以在 onClickbuttonListener 中单击按钮时获取 ID

这是我的xml,我在我的自定义对话框

中加载了这个布局
 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/size_10"
                android:layout_marginRight="@dimen/size_10"
                android:layout_marginTop="@dimen/size_5"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginRight="@dimen/size_15"
                    android:layout_weight="2"
                    android:text="Select Size"
                    android:textColor="@color/colorBlack"
                    android:textSize="18sp" />

                <co.ceryle.radiorealbutton.RadioRealButtonGroup
                    android:id="@+id/radGroupSize"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.5"
                    app:rrbg_animate="true"
                    app:rrbg_animateTexts_enter="cycle"
                    app:rrbg_backgroundColor="@color/colorGrey"
                    app:rrbg_dividerColor="@color/colorPrimary"
                    app:rrbg_checkedButton="@id/radSize_S" //<-- this give u first button as default checked
                    app:rrbg_dividerSize="1dp"
                    app:rrbg_selectorColor="@color/colorPrimary"
                    app:rrbg_selectorFullSize="true"
                    app:rrbg_selectorSize="2dp">

                    <co.ceryle.radiorealbutton.RadioRealButton
                        android:id="@+id/radSize_S"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="top"
                        android:gravity="top"
                        app:rrb_checked="true"
                        app:rrb_ripple="true"
                        app:rrb_rippleColor="@color/colorBlack"
                        app:rrb_text="S"
                        app:rrb_textColor="@color/colorBlack"
                        app:rrb_textFillSpace="true"
                        app:rrb_textSize="11sp" />

                    <co.ceryle.radiorealbutton.RadioRealButton
                        android:id="@+id/radSize_M"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:rrb_ripple="true"
                        app:rrb_rippleColor="@color/colorBlack"
                        app:rrb_text="M"
                        app:rrb_textColor="@color/colorBlack"
                        app:rrb_textSize="11sp" />

                    <co.ceryle.radiorealbutton.RadioRealButton
                        android:id="@+id/radSize_L"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:rrb_ripple="true"
                        app:rrb_rippleColor="@color/colorBlack"
                        app:rrb_text="L"
                        app:rrb_checked="true"
                        app:rrb_textColor="@color/colorBlack"
                        app:rrb_textSize="11sp" />
                </co.ceryle.radiorealbutton.RadioRealButtonGroup>
            </LinearLayout>

我已经在 java.class

中尝试了这些代码
RadioRealButtonGroup radGroupSize = (RadioRealButtonGroup)dialog.findViewById(R.id.radGroupSize);
RadioRealButton radSizeM = (RadioRealButton)dialog.findViewById(R.id.radSize_M);

        radGroupSize.getChildAt(1).setActivated(true); // <----- doesn't work

        radSizeM.setSelected(true); // <----- doesn't work
        radSizeM.setChecked(true); // <----- doesn't work

我想根据 java class

中的变量值将默认选中的按钮更改为另一个按钮

我怎样才能做到这一点?

对我有用

RadioRealButtonGroup radGroupSize=(RadioRealButtonGroup)findViewById(R.id.radGroupSize);

RadioRealButton radSize_S=(RadioRealButton)findViewById(R.id.radSize_S);
RadioRealButton radSize_M=(RadioRealButton)findViewById(R.id.radSize_M);
RadioRealButton radSize_L=(RadioRealButton)findViewById(R.id.radSize_L);

//set position for default radiobutton
radGroupSize.setPosition(2);