How to clear/remove all items in page list adapter

前端 未结 4 1433
旧巷少年郎
旧巷少年郎 2021-02-10 11:54

I\'m using the android paging library to show search result items, is there any way I can clear/remove all the loaded result items, Calling Invalidate on live Paged List refresh

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 12:40

    In Java:

    I cleared all items on in PagedListAdapter by calling invalidate() on DataSource instance like that

    public void clear(){
       movieDataSource.invalidate();
    }
    

    Add this method in your ViewModel then call it in your activity

    movieViewModel.clear();
    movieAdapter.notifyDataSetChanged();
    

    Then Load any data you want

    You can see how I made it in my project.

    Here is the Link: https://github.com/Marwa-Eltayeb/MovieTrailer

提交回复
热议问题