I have a RecyclerView with LinearLayout manager, and I need to interact with last item of RecyclerView in his onScrolled method.
I`m using such code:
lm = new LinearLayoutManager(getActivity());
...
// rv initializing
...
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
Log.d("Last item", ""+lm.findLastCompletelyVisibleItemPosition());
}
});
and when I scroll list abruptly, i have such output in Logcat:
D/Last item: 11
D/Last item: 11
D/Last item: 13
D/Last item: 15
D/Last item: 19
D/Last item: 21
D/Last item: 23
D/Last item: 24
D/Last item: 26
D/Last item: 28
D/Last item: 30
D/Last item: 32
D/Last item: 33
D/Last item: 35
As you can see, some elements just skipped by layout manager. So, my question is: how I can avoid this and get position of all elements?