Listen for the load code implementation

We can onScrollStateChanged the first argument RecycleView objects, to get its layout manager class LayoutManager. We look at the method of this management class source code provided as follows:

//最后一个可见item
public int findLastCompletelyVisibleItemPosition() {
final View child = findOneVisibleChild(getChildCount() - 1, -1, true, false);
return child == null ? NO_POSITION : getPosition(child);
}

//第一个完全可见的item
public int findFirstCompletelyVisibleItemPosition() {
final View child = findOneVisibleChild(0, getChildCount(), true, false);
return child == null ? NO_POSITION : getPosition(child);
}

public int getItemCount() {//拿到总数
final Adapter a = mRecyclerView != null ? mRecyclerView.getAdapter() : null;
return a != null ? a.getItemCount(http://www.amjmh.com) : 0;
}

So, we can get around by LayoutManager item list item list and the total number of fully displayed in the slide list will continue to monitor trigger callback method, we only need to determine whether the item list before and after the full display of the total number of the corresponding item, if it is determined by calling on the pull-down, pull on the method.

Pull-up, pull-down method, we can define an interface UpPullOnScrollListener, we can achieve an Activity.

interface UpPullOnScrollListener {public
/ **
Method to load more data *
* /
public void onLoadMoreData ();

/ **
* refresh method pull data
* /
public void onRefreshData ();
}

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11299173.html