自定义SwipeRefreshLayout 当读取到最后一个Item时候自动加载数据
public class NewSwipeRefreshLayout extends SwipeRefreshLayout { private LoadMoveListener loadMoveListener; public NewSwipeRefreshLayout(Context context) { super(context); } public NewSwipeRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int childCount = getChildCount(); for(int i =0; i< getChildCount(); i++) { View childAt = getChildAt(i); if (childAt instanceof ListView) { ListView listView = (ListView) childAt; //获取到ListView setListViewOnScrollListener(listView); } } } //对ListView设置滚动监听事件 private void setListViewOnScrollListener(ListView listView) { listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { Log.e("onScrollState :", "scrollState: " + scrollState); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { Log.e("onScroll: ", "firstVisibleItem : " + firstVisibleItem + " visibleItemCount: " + visibleItemCount+" totalItemCount: "+totalItemCount); if(firstVisibleItem + visibleItemCount == totalItemCount) { if (loadMoveListener != null) { loadMoveListener.loadMove(); } } } }); } public void setLoadMoveListener(LoadMoveListener listener){ this.loadMoveListener = listener; } interface LoadMoveListener{ void loadMove(); } }