android中ListView滚动刷新

2023-02-23 21:28:21

在做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
view The view whose scroll state is being reported
firstVisibleItem the index of the first visible cell (ignore if visibleItemCount == 0)
visibleItemCount the number of visible cells
totalItemCount the 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
view The view whose scroll state is being reported
scrollState The current scroll state. One of SCROLL_STATE_IDLE, SCROLL_STATE_TOUCH_SCROLL orSCROLL_STATE_IDLE.
  • 作者:evy_gyw
  • 原文链接:https://blog.csdn.net/evy_gyw/article/details/6118196
    更新时间:2023-02-23 21:28:21