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>