我正在使用Paging Library使用来从网络加载数据ItemKeyedDataSource。提取项目后,用户可以对其进行编辑,此更新在内存缓存内部完成(不使用任何数据库,例如Room)。
现在,由于PagedList本身无法更新(在此处讨论),我必须重新创建PagedList并将其传递给PagedListAdapter。
更新本身没有问题,但是在recyclerView使用new 更新之后PagedList,列表会跳至列表的开头,从而破坏先前的滚动位置。无论如何,要在保持滚动位置的同时更新PagedList(例如它如何与Room一起工作)?
数据源是通过以下方式实现的:
public class MentionKeyedDataSource extends ItemKeyedDataSource<Long, Mention> {
private Repository repository;
...
private List<Mention> cachedItems;
public MentionKeyedDataSource(Repository repository, ..., List<Mention> cachedItems){
super();
this.repository = repository;
this.teamId = teamId;
this.inboxId = inboxId;
this.filter = filter;
this.cachedItems = new ArrayList<>(cachedItems);
}
@Override
public void loadInitial(@NonNull LoadInitialParams<Long> params, final @NonNull ItemKeyedDataSource.LoadInitialCallback<Mention> callback) {
Observable.just(cachedItems)
.filter(() …Run Code Online (Sandbox Code Playgroud) android-adapter android-recyclerview android-architecture-components android-jetpack
我有以下代码:
\n val history: Flow<PagingData<Any>> = Pager(PagingConfig(pageSize = 10)) {\n PaginationBaseDataSource(apiService)\n}.flow\n .cachedIn(viewModelScope)\nRun Code Online (Sandbox Code Playgroud)\n当前正在显示没有任何附加参数的项目列表。这工作正常...但现在我希望根据用户可以在前端更改的某些参数来查询此列表,让\xc2\xb4s 说我希望添加参数 3 作为查询。
\n val history: Flow<PagingData<Any>> = Pager(PagingConfig(pageSize = 10)) {\n PaginationBaseDataSource(apiService, 3)\n}.flow\n .cachedIn(viewModelScope)\nRun Code Online (Sandbox Code Playgroud)\n问题是...我怎样才能动态设置这个查询参数?让\xc2\xb4s 说用户而不是3,使用6,然后是9。我怎样才能实现这一点?
\n非常感谢
\nandroid ×1
android-architecture-components ×1
kotlin ×1
kotlin-flow ×1
pagination ×1
paging ×1