CheckBox的使用

首先在XML布局文件中添加CheckBox控件,用于定义复选框

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox" />

 为CheckBox设置监听器

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                
            }
        });

使用isChecked判断复选框是否被选中

 

posted on 2013-12-02 00:24  张茂晨  阅读(171)  评论(0)    收藏  举报