【发布时间】:2018-05-04 07:35:00
【问题描述】:
我使用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 中的变量值将默认选中更改为另一个按钮
我怎样才能做到这一点?
【问题讨论】:
标签: java android layout radio-button checked