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

前端 未结 6 1486
感动是毒
感动是毒 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:18

    When binding the data pass in the previous item as well

      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = getItem(position)
        val previousItem = if (position == 0) null else getItem(position - 1)
        holder.bind(item, previousItem)
      }
    

    Every view then sets a header, which is only made visible if the previous item doesn't have the same header.

        val previousHeader =  previousItem?.name?.capitalize().first()
        val header = item?.name?.capitalize()?.first()
        view.cachedContactHeader.text = header
        view.cachedContactHeader.isVisible  = previousHeader != header
    

提交回复
热议问题