要实现ListView中CheckBox的选中并记录,我的做法是自己写一个Adapter,继承于BaseAdapter,ListView中的CheckBox需要将focusable,clickable的属性都设置为false,防止CheckBox将点击事件拦截,在ListView的onItemClick方法中接收点击事件并对数据进行处理。废话不多说,上代码。
先给大家看一下listview中数据的xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<CheckBox
android:id="@+id/cb"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="false"
android:clickable="false"
android:layout_alignParentRight="true" />
</RelativeLayout>
然后再看main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.c