gpt4 book ai didi

android - RecyclerView 无限滚动

转载 作者:搜寻专家 更新时间:2023-11-01 09:39:09 25 4
gpt4 key购买 nike

我通过以下方式在 listview 中应用滚动:

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();

}
}
}
});

关于android - RecyclerView 无限滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40957618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com