How to implement SwipeRefreshLayout with the new Paging Library

前端 未结 2 1788
情深已故
情深已故 2020-12-15 21:24

I got an activity that shows a list of items to the user and it uses the Paging Library. My problem is that I can\'t reload the list when user swipes down the screen so that

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 21:55

    Add a method in ViewModel class

     public void refresh() {
    
        itemDataSourceFactory.getItemLiveDataSource().getValue().invalidate();
    }
    

    and from the Activity/Fragment you can use

     swipeRefreshLayout.setOnRefreshListener(() -> yourviewModel.refresh());
    

    Hide the refresh layout when the reyclerView gets loaded

    yourViewModel.itemPagedList.observe(this, allProposalModel -> {
    
    
            mAdapter.submitList(model);
            swipeRefreshLayout.setRefreshing(false); //here..
    
    
        });
    

提交回复
热议问题