我应该在“Recyclerview_position_is_bottem”中添加哪个语句来满足现在的recyclelerview位置是执行函数的条件
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (Recyclerview_position_is_bottem){
isScrolled=0;
skip = skip + 5;
remove = 1;
feedItems.add(null);
eventsRecyclerView.notifyItemInserted(feedItems.size());
handler.postDelayed(new Runnable() {
@Override
public void run() {
Loadmore(eventsRecyclerView,1);
}
}, 500);
}
}
});
答案 0 :(得分:1)
第一个/最后一个可见的孩子取决于$('.openModal').on('click', function (e) {
$('#serviceList').find('.modal.active').removeClass('active');
e.preventDefault();
$(this).find('.modal').toggleClass('active');
});
。
如果您使用的是LayoutManager
或LinearLayoutManager
,则可以使用
GridLayoutManager
例如:
int findFirstVisibleItemPosition();
int findFirstCompletelyVisibleItemPosition();
int findLastVisibleItemPosition();
int findLastCompletelyVisibleItemPosition();
对于GridLayoutManager layoutManager = ((GridLayoutManager)mRecyclerView.getLayoutManager());
int firstVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();
,first / last取决于适配器的排序。不要从RecyclerView查询孩子;布局管理器可能优先布局比缓存可见的更多项目。
答案 1 :(得分:1)
您可以使用您在recyclerView上设置的LayoutManager对象,如下所示:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int totalItems = layoutManager.getItemCount();
int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
if (totalItems - 1 == lastVisibleItem){
isScrolled=0;
skip = skip + 5;
remove = 1;
feedItems.add(null);
eventsRecyclerView.notifyItemInserted(feedItems.size());
handler.postDelayed(new Runnable() {
@Override
public void run() {
Loadmore(eventsRecyclerView,1);
}
}, 500);
}
}
});