更新时间:2023-12-05 18:20:34
根据官方文档:
如果您有更精细的更新信号,例如网络API如果要通知列表中的单个项目更新,建议将数据从网络加载到内存中。然后通过包装内存中快照的数据源将数据提供给PagedList。每次内存中的副本更改时,都将使先前的数据源无效,然后可以创建一个新的包装快照的新状态。
If you have more granular update signals, such as a network API signaling an update to a single item in the list, it's recommended to load data from network into memory. Then present that data to the PagedList via a DataSource that wraps an in-memory snapshot. Each time the in-memory copy changes, invalidate the previous DataSource, and a new one wrapping the new state of the snapshot can be created.
PagedList
是不可变的,因此您无法对其进行任何修改。您需要做的是:
PagedList
is immutable so you can't do any modifications against it. What you need to do is:
L
存储服务器您的自定义 DataSource
中的响应。 LoadInitialCallback.onResult()
( PagedList
现在由 L
支持)。 L
。 DataSource.invalidate()
进行配对使用新的数据源,因此调用 DataSource.loadInitial()
来反映步骤3中的更改。L
storing your server responses in your custom DataSource
.LoadInitialCallback.onResult()
(the PagedList
is backing by L
now).L
.DataSource.invalidate()
to pair with a new data source, so DataSource.loadInitial()
is called to reflect the changes in step 3.