Android高级控件(一)——ListView绑定CheckBox实现全选,增加和删除等功能.doc
文本预览下载声明
Android高级控件(一)——ListView绑定CheckBox实现全选,增加和删除等功能
这个控件还是挺复杂的,也是项目中应该算是比较常用的了,所以写了一个小Demo来讲讲,主要是自定义adapter的用法,加了很多的判断等等等等….我们先来看看实现的效果吧!
好的,我们新建一个项目LvCheckBox
我们事先先把这两个布局写好吧,一个是主布局,还有一个listview的item.xml,相信不用多说
activity_main.xml
LinearLayout xmlns:android=/apk/res/android
xmlns:tools=/tools
android:layout_width=match_parent
android:layout_height=match_parent
android:orientation=vertical
RelativeLayout
android:layout_width=match_parent
android:layout_height=50dp
android:background=#238286
TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:layout_centerInParent=true
android:text=ListView绑定CheckBox
android:textColor=#fff /
TextView
android:id=@+id/tv_add
android:layout_width=wrap_content
android:layout_height=wrap_content
android:layout_alignParentRight=true
android:layout_centerVertical=true
android:layout_marginRight=17dp
android:text=增加
android:textColor=#fff /
/RelativeLayout
ListView
android:id=@+id/listview
android:layout_width=match_parent
android:layout_height=0dp
android:layout_weight=1
/ListView
LinearLayout
android:layout_width=match_parent
android:layout_height=50dp
android:orientation=horizontal
Button
android:id=@+id/btn_detele
android:layout_width=match_parent
android:layout_height=match_parent
android:layout_marginRight=1dp
android:layout_weight=1
android:background=#238286
android:text=删除
android:textColor=#fff /
Button
android:id=@+id/btn_select_all
android:layout_width=match_parent
android:layout_height=match_parent
android:layout_marginLeft=1dp
android:layout_weig
显示全部