How to implement load more recyclerview in android

前端 未结 8 1898
盖世英雄少女心
盖世英雄少女心 2020-12-30 06:23

I want to implement load more in Recyclerview. Here is the code. The code is from github. https://gist.github.com/ssinss/e06f12ef66c51252563e

MainActivity code:

8条回答
  •  佛祖请我去吃肉
    2020-12-30 06:43

    Check do you currently have items to scroll down -

    if (! recyclerView.canScrollVertically(1))
    

    If yes - load more items, for example, using HTTP client.

    Full code:

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    if (! recyclerView.canScrollVertically(1)){ //1 for down
                        loadMore();
                    }
                }
            });
    

提交回复
热议问题