How to solve problem with recylerView that is not detecting scrolling of this, if I load exactly 10 items while pagination or when it covers screen

Viewed 36

If I load more than 10 items it works fine. e.g. I select 25 or 50 limits from spinner pagination works fine, but when I select limit 10, then scrolling is not detected inside onScrolled of addOnScrollListener method.

Or if I load the amount of elements that cover the screen, then we need to scroll further items of recyclerView.

RecyclerView creation method

VulnerabilityScanAdapter vulnerabilityScanAdapter = new VulnerabilityScanAdapter( getActivity(), callback, vulnerabilityScanPojoList );

        vulnerabilityScanAdapter.notifyDataSetChanged();
        final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext(),
                LinearLayoutManager.VERTICAL, false);
        vulnerabilityScanRv.setLayoutManager(mLayoutManager);
        vulnerabilityScanRv.setItemAnimator(new DefaultItemAnimator());
        vulnerabilityScanRv.setAdapter(vulnerabilityScanAdapter);

// This is the code for pagination of this recyclerView

vulnerabilityScanRv.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
       
        }

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
          

            if(dy > 0){
                // Scrolling Down
               
                if (totalCount > currentPageCount) {

                    LinearLayoutManager linearLayoutManager =
                            (LinearLayoutManager) recyclerView.getLayoutManager();

                    if (linearLayoutManager != null &&
                            linearLayoutManager.findLastCompletelyVisibleItemPosition() ==
                                    vulnerabilityScanPojoList.size() - 1) {
                        //bottom of list!
                        loadMore();
                    }

                } else {
                    //showSnackForAttributes(true,"No more data avaiable.");
                }

            }else if(dy < 0){
                // Scrolling Up
           }

        }
    });

I have done debugging to know whether the control is going inside onScrolled method while scrolling or not. It goes inside onScrollStateChanged when it reaches to the bottom of the list.

0 Answers
Related