RecyclerView Endless Infinite Scrolling Issue

前端 未结 8 569
长发绾君心
长发绾君心 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:46
    for (int i = start + 1; i < end; i++) {
        studentList.add(add data here) ;
        mAdapter.notifyItemInserted(studentList.size());
    }
    
    0 讨论(0)
  • 2020-12-31 01:55

    I had the same issue once an I solve it using this code ... First .. create this class

    public abstract class EndlessOnScrollListener extends OnScrollListener {
    
        public static String TAG = EndlessOnScrollListener.class.getSimpleName();
    
        // use your LayoutManager instead
        private LinearLayoutManager llm;
    
        public EndlessOnScrollListener(LinearLayoutManager sglm) {
            this.lm = llm;
        }
    
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
    
            if (!recyclerView.canScrollVertically(1)) {
                onScrolledToEnd();
            }
        }
    
        public abstract void onScrolledToEnd();
    }
    

    Second .. in you activity use this

    recyclerView.addOnScrollListener(new EndlessOnScrollListener() {
    
        @Override
        public void onScrolledToEnd() {
            if (!loading) {
                loading = true;
                // add 10 by 10 to tempList then notify changing in data
            }
            loading = false;
        }
    });
    

    This works for me .... I hope it works for you to.

    0 讨论(0)
提交回复
热议问题