gpt4 book ai didi

android - 滚动顶部时的 Recycler View 应该加载数据

转载 作者:行者123 更新时间:2023-11-30 00:09:15 28 4
gpt4 key购买 nike

我正在尝试制作一个聊天应用程序,其中服务器在用户滚动到顶部时仅获取并显示 15 条消息我想加载更多数据并将其附加到数组列表我尝试了 addonScroll 监听器但它仅在用户滚动到底部而不是顶部如果用户滚动到顶部我怎么能获得相同的功能

  public UserAdapter(RecyclerView recyclerView, Activity activity, ArrayList<User> arrayList) {
this.activity = activity;
this.arrayList = arrayList;
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

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

super.onScrolled(recyclerView, dx, dy);
totalItemCount = linearLayoutManager.getItemCount();
lastItemCount = linearLayoutManager.findLastVisibleItemPosition();
Log.d(TAG, "onScrolled: " + lastItemCount + " " + totalItemCount);
if (!isLoading && totalItemCount <= (lastItemCount + visibleThreshold)) {
if (iLoadMore != null) {
iLoadMore.onLoadMore();
isLoading = true;
}
}
}
});
}

我的主要 Activity

    adapter.setUnLoaded();
adapter.setiLoadMore(new ILoadMore() {
@Override
public void onLoadMore() {
arrayList.add(null);//for the progressbar
adapter.notifyItemInserted(arrayList.size() - 1);
Log.d("LOADMORE", "onLoadMore: scrolling working");
BackgroundTask backgroundTask1 = new BackgroundTask(getApplicationContext());
backgroundTask1.delegate = (BackgroundTask.AsynResponse) context;
backgroundTask1.execute("getuser");
}
});

最佳答案

recyclerViewParticulars.addOnScrollListener(new RecyclerView.OnScrollListener() {

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0 ) {
// Scrolling up
Log.d("recyclerviewscroll", "up");



} else if(dy <0 ){
// Scrolling down
Log.d("recyclerviewscroll", "down");

}
}
}

关于android - 滚动顶部时的 Recycler View 应该加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48425042/

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