您的位置:首页 > 移动开发 > Android开发

android开发的CheckBox和RadioButton

2017-11-21 20:38 260 查看
1、改变选择框:以RadioButton为例

<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rb_question"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/c_22"
android:button="@null"
android:drawableLeft="@drawable/radio_question_state"
android:drawablePadding="@dimen/d16px"
android:textSize="@dimen/s32px"
android:paddingBottom="@dimen/d30px"
>

</RadioButton>
在drawable中新建radio_question_state
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="false"
android:drawable="@mipmap/radio_answer_normal"/>
<item
android:state_checked="true"
android:drawable="@mipmap/radio_answer_select"/>
</selector>2、选中状态判断
CheckBox:

cb.setId(i);

cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {

listAnswer.getAnswer().get(compoundButton.getId()).setSelect(isChecked);

}
});RadioButton:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
listAnswer.getAnswer().get(checkId).setSelect(true);

b7ac
if(ActivityUtils.isActivityExist(QuestionActivity.class)){
ActivityUtils.getActivity(QuestionActivity.class).setQuestionListBean(number,listAnswer);
}

}
});
注:尽量不要在自定义控件中设置改变drawableLeft,会出现些奇葩的问题。
最好用CheckBox cb = UIUtils.inflate(context,R.layout.check_question).findViewById(R.id.cb_answer)方式引用;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐