标签:void this 监听回调 led first count listen fir rri
public class UpPullRecyclerViewOnScrollListener extends RecyclerView.OnScrollListener {
//监听回调
private UpPullOnScrollListener listener;
public UpPullRecyclerViewOnScrollListener(UpPullOnScrollListener listener) {
this.listener = listener;
}
/**
* 标记是否正在向上滑动
*/
boolean isUpPull = false;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
//总数
int itemCount = manager.getItemCount();
//最后显示的位置
int lastItemPosition = manager.findLastCompletelyVisibleItemPosition();
if (lastItemPosition == (itemCount - 1) && isUpPull) {
listener.onLoadMoreData();
}
//第一个显示的位置
int fristItemPosition = manager.findFirstCompletelyVisibleItemPosition();
if (fristItemPosition == (0) && !isUpPull){
listener.onRefreshData();
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// 大于0表示正在向上滑动,小于等于0表示停止或向下滑动
isUpPull = dy > 0;
}
}
---------------------
标签:void this 监听回调 led first count listen fir rri
原文地址:https://www.cnblogs.com/liyanyan665/p/11299175.html