如何在ItemKeyedDataSource.LoadInitialParams中使用requestedInitialKey

Sun*_*vel 5 android android-paging-library

我正在学习 android 分页库,一切正常。但是每当我使数据源无效时,只要将新项目添加到列表顶部,列表就会跳转到起始位置。我想在列表中将项目添加到顶部。但是列表应该保持在当前的滚动位置。我想我应该使用 LoadInitialParams.requestedInitialKey 失效时它不为空。但我不确定如何使用此键加载数据以避免列表跳转到起始位置。

我使用 Firestore 数据库作为数据源。我发现提供给回调的requestedInitialKey实际上是当前滚动位置的recyclerview中的最后一个可见项目。我已经尝试了以下方法来获取有关 requestsInitialKey 的数据

.get().startAt(requestedIntitalKey).limit(25)

.get().endBefore(requestedIntitalKey).limit(25)

.get().startAfter(requestedIntitalKey).limit(25)

.get().endAt(requestedIntitalKey).limit(25)
Run Code Online (Sandbox Code Playgroud)

其中 25 是我的页面大小。以上都没有解决问题。有人可以为我提供一个示例,以便列表将停留在其当前滚动位置,只更新内容而不跳转开始吗?