ListView实现的列表,假设是可编辑,可删除的,一般都要提供批量删除功能,否则的话,一项一项的删除体验非常不好,也给用户带来了非常大的麻烦。
实现效果图
详细实现代码
select.xml
主布局文件包括一个ListView另一个隐藏的布局,包括了两个Button一个TextView,默认布局为gone,当监听到长按响应事件时候显示。
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <ListView 8 9 android:id="@+id/list" 10 android:layout_width="match_parent" 11 android:layout_height="match_parent" 12 android:layout_weight="1" 13 android:cacheColorHint="#FFF" > 14 15 </ListView> 16 17 <RelativeLayout 18 19 android:id="@+id/relative" 20 android:layout_width="fill_parent" 21 android:layout_height="50dp" 22 android:gravity="bottom" 23 android:background="@color/lemonchiffon" 24 android:visibility="gone" 25 > 26 <Button 27 28 android:id="@+id/cancle" 29 android:layout_width="wrap_content" 30 android:layout_height="wrap_content" 31 android:text="撤销 |" 32 android:textSize="20sp" 33 android:background="@null" 34 android:layout_centerVertical="true" 35 36 /> 37 <TextView 38 39 android:id="@+id/txtcount" 40 android:layout_width="wrap_content" 41 android:layout_height="wrap_content" 42 android:text="共计" 43 android:textSize="15sp" 44 android:layout_centerInParent="true" 45 46 /> 47 48 <Button 49 50 android:id="@+id/delete" 51 android:layout_width="wrap_content" 52 android:layout_height="wrap_content" 53 android:text="| 删除" 54 android:textSize="20sp" 55 android:background="@null" 56 android:layout_alignParentRight="true" 57 android:layout_centerVertical="true" 58 /> 59 60 61 </RelativeLayout> 62 </LinearLayout>
item.xml
包括一个TextView 一个CheckBox
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="horizontal" > 6 7 <TextView 8 android:id="@+id/txtName" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:layout_alignParentLeft="true" 12 android:layout_centerVertical="true" 13 android:layout_gravity="center_vertical" 14 android:layout_marginLeft="5dp" 15 android:layout_weight="1" 16 android:text="444444444444" 17 android:textSize="17sp" 18 android:textColor="#333" /> 19 20 <CheckBox 21 android:id="@+id/check" 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 android:visibility="gone" 25 android:clickable="false" 26 /> 27 </LinearLayout>