Pagination while scrolling recycler view to the top

China☆狼群 提交于 2019-12-04 13:29:33

Code inside adapter.Please note that granular updates is better than calling notifydataset changed.Reference

public void addlisttop(List<MyInformationClass> list)
     {
        for(int i=0;i<list.size();i++)
        {
            myinformation.add(i,list.get(i));
            notifyItemInserted(i);
        }
    }  

the code to add items when the list is reaches the zero position

 myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            int itemno=myLayoutManager.findFirstVisibleItemPosition();
            if(itemno==0)additems();
        }
    });

Code to add items

private void additems()
{
    MyInformationClass myInformationClass=new MyInformationClass();
    List<MyInformationClass> list=new ArrayList<>(10);
    for(int i=0;i<10;i++)
    {
        myInformationClass=new MyInformationClass();
        myInformationClass.maintext="BulkListItem"+ String.valueOf(number);
        myInformationClass.subtext="subtext";
        list.add(myInformationClass);
        number=number+1;
    }
    myRecycleAdapter.addlisttop(list);
}

for complete reference.Refer this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!