How to clear/remove all items in page list adapter

前端 未结 4 1431
旧巷少年郎
旧巷少年郎 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条回答
  • 2021-02-10 12:22

    submitting null clear the currently loaded page list

      productSearchResultItemAdapter.submitList(null)
    
    0 讨论(0)
  • 2021-02-10 12:32

    Before invalidate, clear your list data item. Like we did in simple way:

    list.clear();
    adapter.notifyDataSetChanged();
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-10 12:42

    If you're working with PagingDataAdapter, searchAdapter.submitData(lifecycle, PagingData.empty()) works

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