CheckBox:复选框
1.有两种状态:
选中状态(true),未选中状态(false)
2.属性:
android:
CheckBox的默认android:checked属性为false。
checkBox的OnCheckedChangeListener事件检查勾是否勾选。
样例程序中有3个CheckBox和1个TextView,TextView事实演示了有多少CheckBox被勾选了以及被勾选的CheckBox的名称。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="篮球" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="足球" /> <CheckBox android:id="@+id/checkBox3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="乒乓球" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0项选择" /> </LinearLayout>