Android RecyclerView adding pagination

前端 未结 3 917
孤独总比滥情好
孤独总比滥情好 2021-01-06 10:33

I created a RecyclerView for my application and trying to find a way to stop huge requests, I want to get the results 10 by 10 with a progress bar. My server will send the r

3条回答
  •  伪装坚强ぢ
    2021-01-06 10:53

    You can try this approach:

      mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
    {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy > 0) //check for scroll down
            {
                visibleItemCount = mLayoutManager.getChildCount();
                totalItemCount = mLayoutManager.getItemCount();
                pastVisibleItems = mLayoutManager.findFirstVisibleItemPosition();
    
                if (loading) {
                    if ((visibleItemCount + pastVisibleItems) >= totalItemCount) {
                        loading = false;
                        if (adapter.countOfShowing < adapter.allChallenges.size()) {
                            Log.e("...", "Last Item Wow !");
                            adapter.increaseCountOfShowing();
                            adapter.notifyDataSetChanged();
                        }
                        loading = true;
                        //Do pagination.. i.e. fetch new data
                    }
                }
            }
        }
    });
    

提交回复
热议问题