【发布时间】:2021-10-29 21:45:26
【问题描述】:
/*--- Load News Feed in Recycler View ---*/
private void loadNewsFeed(){
CollectionReference collectionReference = firebaseFirestore.collection("News Feed");
query = collectionReference
.orderBy("newsFeedId", Query.Direction.DESCENDING);
PagingConfig config = new PagingConfig(1,
1,
false);
FirestorePagingOptions<ModelNewsFeed> options = new FirestorePagingOptions.Builder<ModelNewsFeed>()
.setLifecycleOwner(this)
.setQuery(query, config, ModelNewsFeed.class)
.build();
adapterNewsFeedListFireStorePaginationAds = new AdapterNewsFeedListFireStorePaginationAds(options, this);
newsFeedRv.setAdapter(adapterNewsFeedListFireStorePaginationAds);
}
我在“.setQuery(query, config, ModelNewsFeed.class)”处收到错误
Error: .setQuery(query, config, ModelNewsFeed.class)
^
method Builder.setQuery(Query,Config,Class<ModelNewsFeed>) is not applicable
(argument mismatch; PagingConfig cannot be converted to Config)
method Builder.setQuery(Query,Config,SnapshotParser<ModelNewsFeed>) is not applicable
(argument mismatch; PagingConfig cannot be converted to Config)
纠正这个错误的解决方案是什么?
我正在尝试从
迁移第 2 页: androidx.paging:paging-runtime:2.1.2
到
第 3 页:
androidx.paging:paging-runtime:3.0.1.
【问题讨论】:
-
你试过只打电话给
.setQuery(query, ModelNewsFeed.class)吗?是这样的吗? -
我必须使用分页。和 .setQuery(query, ModelNewsFeed.class) 非常适合一次加载所有项目。我已按照firebaseopensource.com/projects/firebase/firebaseui-android/… 中提到的步骤进行操作。但是对于分页它给了我一个错误。
-
我已经更新了错误消息的屏幕截图,我得到了更多的说明。
-
你是如何导入 PagingConfig 的?请编辑您的问题并添加相应的行。
-
首先我替换了gradle文件中的依赖。然后从 firebaseopensource.com/projects/firebase/firebaseui-android/… 复制了 PagingConfig 的代码。按 Alt+Enter 导入后,这是在 Java 文件“import androidx.paging.PagingConfig;”中导入的。然后这个错误开始出现。如果还有什么想知道的,请告诉我。
标签: android google-cloud-firestore android-recyclerview pagination android-paging-3