RecyclerView Endless Infinite Scrolling Issue

前端 未结 8 596
长发绾君心
长发绾君心 2020-12-31 01:36

I am trying to implement Endless Infinite Scrolling with RecyclerView, but I am only getting first 10 records, not getting next 10 records and even not getting any progress

8条回答
  •  無奈伤痛
    2020-12-31 01:43

            mAdapter.setOnLoadMoreListener(new OnLoadMoreListener() {
                        @Override
                        public void onLoadMore() {
                            //add null , so the adapter will check view_type and show progress bar at bottom
                            studentList.add(null);
                            mAdapter.notifyItemInserted(studentList.size() - 1);
    
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    //   remove progress item
                                    studentList.remove(studentList.size() - 1);
                                    mAdapter.notifyItemRemoved(studentList.size());
                                    //add items one by one
                                    int start = studentList.size();
                                    int end = start + 10;
    
                                    for (int i = start + 1; i < end; i++) {
       // studentList.add();
                                        mAdapter.notifyItemInserted(studentList.size());
                                    }
                                    mAdapter.setLoaded();
                                   //or you can add all at once but do not forget to call mAdapter.notifyDataSetChanged();
                                }
                            }, 2000);
                        }
                    });
    

    ok so you inserted progress bar, and then you've removed it as well but you never inserted the next student to show... something like studentList.add();

    I hope that solved your problem... good luck..

提交回复
热议问题