android开发的CheckBox和RadioButton

1、改变选择框:以RadioButton为例




在drawable中新建radio_question_state



    
    
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);
                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)方式引用;


你可能感兴趣的:(android开发日记)