gpt4 book ai didi

android - 使用 RxJava 时在分页 3 库中刷新

转载 作者:行者123 更新时间:2023-12-04 23:39:00 25 4
gpt4 key购买 nike

homeViewModel.pagingDataFlow.subscribe(expensesPagingData -> {
expenseAdapter.submitData(getLifecycle(), expensesPagingData);
}, throwable -> Log.e(TAG, "onCreate: " + throwable.getMessage()));

// ViewModel

private void init() {
pagingDataFlow = homeRepository.init();
CoroutineScope coroutineScope = ViewModelKt.getViewModelScope(this);
PagingRx.cachedIn(pagingDataFlow, coroutineScope);

}

// Repository
public Flowable<PagingData<ExpensesModel>> init() {
// Define Paging Source
expensePagingSource = new ExpensePagingSource(feDataService);
// Create new Pager
Pager<Integer, ExpensesModel> pager = new Pager<Integer, ExpensesModel>(

new PagingConfig(10,
10,
false,
10,
100),
() -> expensePagingSource); // set paging source

// inti Flowable
pagingDataFlow = PagingRx.getFlowable(pager);
return pagingDataFlow;
}


I have tried to invalidate still not working.
public void invalidatePageSource() {
if (expensePagingSource != null) {
expensePagingSource.invalidate();
}
}

使用费用适配器刷新适配器时.refresh()
当 Pager 期望创建一个新实例时,一个 PagingSource 实例被重新使用。确保传递给 Pager 的 pagingSourceFactory 总是返回一个新的 PagingSource 实例。
这是我用来获取数据的可流动对象。
任何帮助将不胜感激。

最佳答案

所以而不是

val pagingSource = PagingSource()

return Pager() {
pagingSource
}.flow
用这个

return Pager() {
PagingSource()
}.flow
基本上,它有助于存储分页资源的引用,稍后当您调用 refresh() 时,适配器会使用该引用对其调用无效。

关于android - 使用 RxJava 时在分页 3 库中刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66803759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com