Android 分页库不使用页码,但具有显式的下一组 id
Android 分页库的 PagingSource 使用 key,
PagingSource<Int, Item>
其中第一个参数是页码。如果服务器不使用页码,而是返回(对于每个请求)客户端应在下一个请求中请求的项目 ID 列表,该怎么办? Paging库支持这种场景吗?
Android paging library's PagingSource uses key like
PagingSource<Int, Item>
where the first parameter is the page number. What if the server, instead of using a page number, returns (for each request) a list of items ids the client should request for in the next request? Does Paging library support this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您控制泛型类型和 load() 方法时,PagingSource 可以支持您想要的任何任意键类型。
如果您询问 Room 的 Paging 集成,则
PagingSource仅支持位置键(不支持 page#),但您写入数据库的内容以及用于从数据库加载的键与您用来从网络加载的内容是分开的。
对于网络+数据库场景,您应该研究
RemoteMediator
,它通过数据库支持分页,并提供钩子供您在数据库没有更多缓存项时从网络加载。这里有一个关于 DAC 的很棒的指南:https://developer .android.com/topic/libraries/architecture/paging/v3-network-db
PagingSource can support any arbitrary key type you want as you control both the generic type and the load() method.
If you are asking about Room's Paging integration, only positional keys (not page#) are supported with
PagingSource<Int, Value>
, but what you write into the DB and the keys you use to load from DB are separate from what you use to load from network.For network + DB scenario you should look into
RemoteMediator
which powers Paging via DB and provides hooks for you to load from network when DB has no more cached items.There is a great guide on DAC here: https://developer.android.com/topic/libraries/architecture/paging/v3-network-db