android中ListView滚动刷新

在做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 togetView(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 orSCROLL_STATE_IDLE.
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页