我找到了这段代码并将其改编为我的项目
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = mLayoutManager.getChildCount();
//totalItemCount = mLayoutManager.getItemCount();
int[] firstVisibleItems = null;
firstVisibleItems = mLayoutManager
.findFirstVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
pastVisibleItems = firstVisibleItems[0];
}
if (!loading && visibleItemCount <= (pastVisibleItems + visibleThreshold)) {
// End has been reached
// Do something
Log.d(TAG, "onLoadMoreListener ");
getTagResults(mQuery, mMinId, mMaxId);
// if (onLoadMoreListener != null) {
// onLoadMoreListener.onLoadMore();
// }
loading = true;
}
}
但这不适用于线性布局。我已经为所有其他布局找到了很多代码但是我无法找到如何在达到结束时加载更多结果。
答案 0 :(得分:8)
使用以下代码
RecyclerView.LayoutManager layoutManager;
layoutManager = new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(layoutManager);