如何在“回收者视图"中获取当前可见的物品 [英] how to get current visible item in Recycler View
本文介绍了如何在“回收者视图"中获取当前可见的物品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何获取"RecyclerView"当前可见的项目.已经尝试过recyclerview的其他方法,但是我无法获得解决方案,所以请帮助并指导我
How i can get the "RecyclerView" current visible item. already try different methods of recyclerview but i can't get the solution so please help and guide me
推荐答案
private RecyclerView.OnScrollListener recyclerViewOnScrollListener = 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 visibleItemCount = linearLayoutManager.getChildCount();
int totalItemCount = linearLayoutManager.getItemCount();
int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
final int lastItem = firstVisibleItemPosition + visibleItemCount;
}
};
全局声明LinearLayoutManger,
Declare LinearLayoutManger globally,
私有LinearLayoutManager linearLayoutManager;
private LinearLayoutManager linearLayoutManager;
像这样初始化RecyclerView,
Initialize RecyclerView like this,
linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
notificationListRecyclerView.setLayoutManager(linearLayoutManager);
notificationListRecyclerView.addOnScrollListener(recyclerViewOnScrollListener);
这篇关于如何在“回收者视图"中获取当前可见的物品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文