How to add date separators in recycler view using Paging Library?

前端 未结 6 1412
感动是毒
感动是毒 2021-02-05 10:34

After a lot of searching, I know its possible with regular adapter, but I have no idea how to do it using Paging Library. I don`t need code just a clue.

Example

6条回答
  •  情书的邮戳
    2021-02-05 11:02

    To add separators, you essentially have 2 options:

    1. View-based, you explicitly include separators as an 'item' in the list and define a new viewtype for those separators. Allows the list to re-use the separator views but means you need to take the separators into account when defining the data.
    2. Data-based, each item actually has a separator view, but it only shows on specific items. Based on some criteria you show or hide it whilst binding the view-holder.

    For the paging library only option 2 is viable since it only partially loads the data and inserting the separators becomes much more complicated. You will simply need to figure out a way to check if item x is a different day than item x-1 and show/hide the date section in the view depending on the result.

提交回复
热议问题