activity_main.xml
<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" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全选" android:layout_weight="1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="反 选" android:layout_weight="1" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全不选" android:layout_weight="1" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" android:layout_weight="1" /> </LinearLayout> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:id="@+id/listveiw" android:layout_width="match_parent" android:layout_height="match_parent" ></ListView> </LinearLayout>
listveiw.xml
如果ListView的Item中包含CheckBox,由于CheckBox的焦点优先级高于ListView,所以当选中ListView时,ListView将不会有选中的状态,解决的方法就是在checkbox组件中加一属性:android:focusable="false"
<?xml version="1.0" encoding="