如何在使用分页列表适配器时对API进行分页

时间:2018-07-21 10:26:03

标签: kotlin retrofit retrofit2 pagedlist android-jetpack

我有一个应用程序,因为大量数据都来自Web服务响应。我正在使用PagedListAdapter,但是我认为它只能在Room数据库中进行分页。我的问题是,有没有办法使用此PagedListAdapter对API进行分页? 注意:我有一个传递给适配器的diff util类,并且正在端点中使用@Query("page") and @Query("per_page")来使用Retrofit

class PostDiffCallback : DiffUtil.ItemCallback<ProductPost>() {

    override fun areItemsTheSame(oldItem: ProductPost?, newItem: ProductPost?) = oldItem?.productId == newItem?.productId

    override fun areContentsTheSame(oldItem: ProductPost?, newItem: ProductPost?) = oldItem?.equals(newItem) ?: false

}

感谢您的帮助

0 个答案:

没有答案