Q: How to check only visible items in RecyclerView I called one API and loaded a list of data in RecyclerView. Now User clicks any one of the item then a new page open. In this new page, I am calling a new API which are able to fetch data. My problem is that if internet speed it too much slow, it takes too much time to be loaded. So i am trying to optimize the performance. I do not know which logic will be best. 
I am trying one logic. When user scroll to first page ( Recycler view). I will call details page API and preload data and keeps it in locally db (sqlite). So when i clicked on any item, details page will be open and check if locally has data or not. if locally has data, it will display using locally. So i think it should be faster.
So for applying above logic,I will have to call API during only visible items on Recycler view. So i am using addOnScrollListener but it calls many times. I just need to call it which items are visible to user. If there are 3 item visible then 1 time it should be call but it is calling many times and api is calling many times.
 recyclerView.addOnScrollListener(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) {

                    if (dy < 0) {
                        // Recycle view scrolling up...

                    } else if (dy > 0) {
                        // Recycle view scrolling down...
                        int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
                        int findFirstCompletelyVisibleItemPosition = layoutManager.findFirstCompletelyVisibleItemPosition();
                        int findLastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
                        int findLastCompletelyVisibleItemPosition = layoutManager.findLastCompletelyVisibleItemPosition();

                        Log.e("","firstVisiblePosition ="+firstVisiblePosition
                                +"\nfindFirstCompletelyVisibleItemPosition ="+findFirstCompletelyVisibleItemPosition
                                +"\nfindLastVisibleItemPosition ="+findLastVisibleItemPosition
                                +"\nfindLastCompletelyVisibleItemPosition ="+findLastCompletelyVisibleItemPosition);

                        // here many times it is checking in locally.
                        //check locally has data
                        //if yes
                        //Call API.

                    }
                }
            });


A: I believe onScrolled might be called too frequently for what you're trying to solve.  Try checking the callback in LayoutManager instead since 

A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.

Possibly check if these callbacks will work for you onItemsAdded, onLayoutChildren, or onAddFocusables ...I can't post 3 links =(
