Reputation: 253
I found this code and adapted it to my project
@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;
}
}
but this doesnt work it works for linear layout though. I have found lots of code for all the other layouts but i cant find how to load more results when end is reached.
Upvotes: 3
Views: 3335
Reputation: 541
Use following code
RecyclerView.LayoutManager layoutManager;
layoutManager = new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(layoutManager);
Upvotes: 8