首页 > 解决方案 > Android Paging3 insertSeparators 无法按预期工作

问题描述

我正在尝试在我的列表中添加分隔符,例如 A、“Apple”、“Anaconda”、B“Boys”、“Bostwana”,但是,insertSeparators似乎并没有表明我们何时处于开头或结尾。

adapter.submitData(pagingData.insertSeparators { before, after ->
    val afterDate = DateItem().withDate(after?.transactionDate)
    val beforeDate = DateItem().withDate(before?.transactionDate)

    if (after != null && (before == null || afterDate.toString() != beforeDate?.toString())) {
        return@insertSeparators afterDate
    }
    return@insertSeparators null
})

我的期望是before在开始时after为空,而在列表末尾为空。但它永远不会为空,因此很难知道我们何时处于开始或结束。

标签: androidandroid-architecture-componentsandroid-paging

解决方案


显然这是 paging3 库 3.0.0alpha10 版本上的一个已知错误。

https://issuetracker.google.com/issues/172254056


推荐阅读