Android checkBox

checkBox
     状态:选中(true),未选中(false)
     属性:
          checked="true/false";
private CheckBox  checkbox ;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
              setContentView(R.layout. activity_main);
               checkbox=(CheckBox) findViewById(R.id. checkbox);
               //通过设置checkbox的监听事件来对checkbox是不是被选中。
               //new一个匿名的内部类
               checkbox.setOnCheckedChangeListener( new OnCheckedChangeListener() {
                      @Override
                      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            // 通过onCheckedChanged来监听当前的 checkbox是否被选中
                            if(isChecked){
                                  String text=checkbox.getText().toString();
                                  Log. i("tag", text );
                           }
                     }
              });
       }
 
 
 <CheckBox
        android:checked ="true"
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox" />
stareblankly.cn
原文地址:https://www.cnblogs.com/stareblankly/p/4829243.html