2

I try to implement load more when scroll to bottom of recyclerView It's work when my XML only have recyclerView but when i put it to scrollview and setNestedScrollingEnabled(false) it doesn't work

XML " Requirement " - The orange area is static layout - The green area is dynamic items and when i scoll to bottom orange area must be scroll down too

    mAdapter = new RecyclerViewCommentAdapter(commentList, userInformationList);
    mRecyclerViewComment = (RecyclerView) rootView.findViewById(R.id.recyclerViewComment);
    mRecyclerViewComment.setNestedScrollingEnabled(false);
    mRecyclerViewComment.setHasFixedSize(true);
    mRecyclerViewComment.setItemViewCacheSize(30);
    mRecyclerViewComment.setDrawingCacheEnabled(true);
    mRecyclerViewComment.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

    mLayoutManager = new LinearLayoutManager(mContext);
    mRecyclerViewComment.setLayoutManager(mLayoutManager);
    mRecyclerViewComment.setItemAnimator(new DefaultItemAnimator());
    mRecyclerViewComment.setAdapter(mAdapter);

    // Scroll //
    mRecyclerViewComment.addOnScrollListener(new RecyclerView.OnScrollListener()
    {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy)
        {
            Log.d(getClass().getName(), "dy = " + dy);
            if(dy > 0) //check for scroll down
            {
                visibleItemCount = mLayoutManager.getChildCount();
                totalItemCount = mLayoutManager.getItemCount();
                pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
                Log.d(getClass().getName(), "totalItemCount = " + totalItemCount);
                if (loading)
                {

                    if ( (visibleItemCount + pastVisiblesItems) >= totalItemCount && (visibleItemCount + pastVisiblesItems) >= TOTAL_FIRST_LOAD)
                    {
                        loading = false;
                        loadMoreKey();
                    }

                }
            }
        }
    });

}

I try to debug 'dy' it's always 0

JustKhit
  • 407
  • 3
  • 9
  • Can you share the requirement to put a RecyclerView inside a ScrollView? – Anuj Jun 23 '17 at 11:22
  • Thanks @basilisk Checkout my edited answer – JustKhit Jun 23 '17 at 11:30
  • 2
    From the designs, it seems you do not need the scroll view. If you want the orange area to scroll with the list, then add it as another item in RecyclerView (see https://stackoverflow.com/a/26245463/493321 ). If you want to to be static and not scroll at all, put both the views in a LinearLayout. In most cases, nested scrolling is not a good idea. – Anuj Jun 23 '17 at 11:58
  • @basilisk Solved Thanks a lot XD – JustKhit Jun 23 '17 at 20:42

1 Answers1

1

dy is 0 because RecyclerView is not scrolling, its fitting its content in the scroll view. So, the view which is scrolling is ScrollView.

This is not a particularly good implementation as all the views in RecyclerView are inflated at the same time which beats the purpose of RecyclerView which is to reuse the ViewHolders when user scrolls and dynamically inflate elements in the View to save memory usage.

Try fixing the height of the RecyclerView and don't use wrap_content or match_parent in the height property of your RecyclerView