android大讲堂——listview详解

来源:互联网 发布:一键安装java环境 编辑:程序博客网 时间:2024/06/07 04:41

本期讲解listview控件,包含基本用法、回调方法、页眉页脚等

1、基本用法

a) 官方定义:A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view.

b) 五个xml属性:

android:divider:Drawable or color to draw between list items. 

android:dividerHeight:Height of the divider. 

android:entries:Reference to an array resource that will populate the ListView. 

android:footerDividersEnabled:When set to false, the ListView will not draw the divider before each footer view. 

android:headerDividersEnabled:When set to false, the ListView will not draw the divider after each header view. 

android:scrollbars: 滚动条的显示方式(垂直、水平、无)

android:fastScrollEnabled:是否快速滑动

android:minHeight,android:minWidth:最小高宽

c) 父类

java.lang.Object
↳android.view.View    ↳android.view.ViewGroup     ↳android.widget.AdapterView<T extends android.widget.Adapter>      ↳android.widget.AbsListView       ↳android.widget.ListView

d)公共构造函数

public ListView (Context context)

public ListView (Context context, AttributeSet attrs)

public ListView (Context context, AttributeSet attrs, int defStyle)

e) 公共方法

addFooterView(View v) addHeaderView(View v) 添加页眉页脚(还有删除)

getFooterViewsCount() getHeaderViewsCount() 获得页眉页脚的个数



2、回调方法

setOnItemClickListener:每一项点击事件监听
setOnLongClickListener:长按事件监听

3、页眉页脚

基本可实现的效果,如:上拉刷新、下拉加载更多、listview顶部添加图片或自定义布局

















0 0
原创粉丝点击