在我的 ViewModel 中,我使用
加载数据private val pagingConfig = PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setInitialLoadSizeHint(INITIAL_LOAD_SIZE_HINT)
.setPageSize(PAGE_SIZE)
.build()
val notificationList = LivePagedListBuilder<Long, Notification>(dataSourceFactory, pagingConfig).build()
效果很好。但是,当我的数据发生变化时,LiveData<PagedList<Notification>>
没有得到通知。我能做些什么来触发 LiveData
刷新(ViewModel
知道更改何时发生)。
最佳答案
您可以使用 DataSource
中的 invalidate()
方法触发数据更新。
When using the Paging Library, it's up to the data layer to notify the other layers of your app when a table or row has become stale. To do so, call
invalidate()
from theDataSource
class that you've chosen for your app.
关于android-architecture-components - 强制分页库数据源刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53172300/