How to delete/remove PagedListAdapter item

前端 未结 4 729
既然无缘
既然无缘 2021-02-12 18:09

Currently I am using Android Architecture Components for App development everything is working along with paging library Now I want to remove recyclerview Item

4条回答
  •  無奈伤痛
    2021-02-12 18:47

    Since you cannot directly modify the data that you have in the PagedList as I believe its immutable, the key to implementing the removal of items in this situation is maintaining a backing dataset somewhere in your code that represents all the data that you have received so far. An ArrayList worked for me.

    When you want to remove an item, remove it from your backing dataset and call invalidate on your data source. This will trigger the loadInitial() call, in which you can pass your backing dataset to the callback.onResult() function. Your PagedListAdapter will use the DiffUtil.ItemCallback you supplied to smartly determine that there has been an update to its data and will update itself accordingly.

    This tutorial helped me understand the correct flow to use in order to properly delete an item while using the paging library: https://medium.com/@FizzyInTheHall/implementing-swipe-to-delete-with-android-architecture-components-a95165b6c9bd

    The repo associated with the tutorial can be found here: https://gitlab.com/adrianhall/notes-app

提交回复
热议问题