gpt4 book ai didi

android - RecyclerView 页脚未显示

转载 作者:行者123 更新时间:2023-11-30 01:09:14 25 4
gpt4 key购买 nike

我试图在 RecyclerView 无限滚动中显示页脚,但页脚有时显示得太快有时根本不显示。给定的代码有问题吗??

 public class CustomRecyclerViewScrollListener extends    RecyclerView.OnScrollListener {
int visibleCount = 0;
int totalItemCount = 0;
int pastVisibleItems = 0;
int lastVisibleItem=0;

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

visibleCount = llm.getChildCount();
totalItemCount = llm.getItemCount();
pastVisibleItems = llm.findFirstVisibleItemPosition();
lastVisibleItem=llm.findLastVisibleItemPosition();
if (!isLoading && !dataFinished && list.size() % 10 == 0) {
if ((visibleCount + pastVisibleItems) >= totalItemCount) {
isLoading = true;
loadMore();
adapter.showViewHolderFooter();

}
}
} else {
adapter.hideViewHolderFooter();

}
}

最佳答案

private int firstVisibleItem, visibleItemCount,totalItemCount,pastVisiblesItems;
private boolean loading = true;

reyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) //check for scroll down
{
visibleItemCount = mLayoutManager.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();

if (loading) {
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
loading = false;
expandapleInt++;

//Your operation
}
}
}
}
});

在我的代码中,为每个操作设置 loading = true; 在您的代码中,在每次加载开始之前将 isLoading 设置为 false

关于android - RecyclerView 页脚未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38582632/

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