您的位置:首页 > 移动开发 > Android开发

android中ListView滚动刷新

2011-09-06 17:06 375 查看
在做ListView加载数据时如果数据量大的话会造成加载时间过长而卡屏,所以为了解决这个问题,查看了SDK,

在OnScrollListener中有两个方法

只要重写这两个方法就可以实现滚动加载,例如:

public void onScroll(AbsListView v, int firstVisibleItem,

int visibleItemCount, int totalItemCount) {

lastItem = firstVisibleItem + visibleItemCount - 1;

if (adapter.count == lastItem) {

adapter.count += 10;

adapter.notifyDataSetChanged();

}

}

public void onScrollStateChanged(AbsListView view, int scrollState) {

// TODO Auto-generated method stub

Log.i("onScrollStateChanged", "onScrollStateChanged");

}


public abstract void onScroll (AbsListView view,
int firstVisibleItem, int visibleItemCount, int totalItemCount)

Since: API Level 1

Callback method to be invoked when the list or grid has been scrolled. This will be called after the scroll has completed


Parameters

viewThe view whose scroll state is being reported
firstVisibleItemthe index of the first visible cell (ignore if visibleItemCount == 0)
visibleItemCountthe number of visible cells
totalItemCountthe number of items in the list adaptor


public abstract void onScrollStateChanged (AbsListView view,
int scrollState)

Since: API Level 1

Callback method to be invoked while the list view or grid view is being scrolled. If the view is being scrolled, this method will be called before the next frame of the scroll is rendered. In particular, it will be called before any calls to
getView(int,
View, ViewGroup)
.


Parameters

viewThe view whose scroll state is being reported
scrollStateThe current scroll state. One of
SCROLL_STATE_IDLE
,
SCROLL_STATE_TOUCH_SCROLL
or
SCROLL_STATE_IDLE
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: