Home » Android » android – Can't find RecyclerView visible item position inside NestedScrollView

android – Can't find RecyclerView visible item position inside NestedScrollView

Posted by: admin May 14, 2020 Leave a comment

Questions:

How do I get the first/ last completely visible item in a recyclerview if it is inside a NestedScrollView and the recycler has nestedScrollingEnabled="false" for smooth scrolling with other views above the RecyclerView.

All these functions

int findFirstVisibleItemPosition();
int findFirstCompletelyVisibleItemPosition();
int findLastVisibleItemPosition();
int findLastCompletelyVisibleItemPosition();

either return the first/last item created in the recyclerView.

I want to find the current visible item because I want to make the RecyclerView scroll infinitely and I should fetch data if only a few items are left to scroll.

Thanks

How to&Answers:

Well I couldn’t find any way in which two RecyclerView could be inside a NestedScrollView and still say which item is visible on the screen.

So my solution was to remove the NestedScrollView and make the Vertical RecycelerView the main view in the page and add the Horizontal RecyclerView as the first item of on Vertical Recycler. As I only wanted to know the position for the Vertical Recycler, I can get that now by using any of the methods mentioned in the question.