gpt4 book ai didi

java - RecyclerView 无限滚动到顶部(聊天应用程序)

转载 作者:行者123 更新时间:2023-11-29 23:40:21 25 4
gpt4 key购买 nike

我目前正在使用 THIS TECHNIQUE让我的 RecyclerView 无穷无尽;但问题是我想要它正好相反。当用户像聊天信使一样向上滚动时,我想将数据加载到适配器中。

private int previousTotal = 0;
private boolean loading = true;
private int visibleThreshold = 5;
int firstVisibleItem, visibleItemCount, totalItemCount;

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

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

visibleItemCount = mRecyclerView.getChildCount();
totalItemCount = mLayoutManager.getItemCount();
firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();

if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
// End has been reached

Log.i("Yaeye!", "end called");

// Add to data set
chatMessages.add(0, new Message("Hello World!"));

loading = true;
}
}
});

最佳答案

关于java - RecyclerView 无限滚动到顶部(聊天应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51921322/

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