我以如下方式应用于scroll inlistview
:
mylistview.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
boolean loadMore = /* maybe add a padding */
firstVisibleItem + visibleItemCount >= totalItemCount;
if(loadMore) {
int tempLimit = totalItemCount/50 + 1;
FriendsAdapter temp = (FriendsAdapter) friendsList.getAdapter();
if (temp!=null&&temp.ev.size()>0&&temp.ev.size()+50<=tempLimit*50) {
limit = tempLimit;
new GetFriendRequestsAsync(getActivity(),String.valueOf(limit)).execute();
}
}
}
});
现在我需要更新它并使用
RecycleView
。如何将此应用于RecycleView
?每50件,我就做点什么。 最佳答案
您可以使用以下选项:
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
boolean loadMore = /* maybe add a padding */
lastVisibleItemPosition + 6 >= totalItemCount;
if (loadMore) {
int tempLimit = totalItemCount / 50 + 1;
FriendsAdapter temp = (FriendsAdapter) friendsList.getAdapter();
if (temp != null && temp.ev.size() > 0 && temp.ev.size() + 50 <= tempLimit * 50) {
limit = tempLimit;
new GetFriendRequestsAsync(getActivity(), String.valueOf(limit)).execute();
}
}
}
});