[英]I added a map as a field in my Firestore DB document with a sub field inside, and I am facing issues to my RecyclerView
I am facing issues with my RecyclerView in displaying my app's candidates when I include the added map field in my query.当我在查询中包含添加的地图字段时,我的 RecyclerView 在显示我的应用程序的候选项时遇到了问题。 I also have created an index for this query but still, nothing comes out of my RecyclerView.
我还为这个查询创建了一个索引,但我的 RecyclerView 仍然没有任何内容。
This is the UPDATED query code.这是更新的查询代码。 If there is something wrong with the coding, please do notify me.
如果编码有问题,请通知我。
FirebaseUser user = mAuth.getCurrentUser();
String voterID = user.getUid();
Query query = notebookRef.whereEqualTo("registrationStatus", "Accepted").whereEqualTo( voterID, false).orderBy("candidateFullName", Query.Direction.ASCENDING);
FirestoreRecyclerOptions<VoterCandidateItem> options = new FirestoreRecyclerOptions.Builder<VoterCandidateItem>()
.setQuery(query, VoterCandidateItem.class)
.build();
adapter = new VoterCandidateAdapter(options);
recyclerView = findViewById(R.id.candidateList);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
recyclerView.setItemAnimator(null);
This is the UPDATED screenshot of Firestore DB:这是 Firestore DB 的更新截图:
The following query:以下查询:
Query query = notebookRef
.whereEqualTo("registrationStatus", "Accepted")
.whereEqualTo(voterID, false)
.orderBy("candidateFullName", Query.Direction.ASCENDING);
Requires an index , otherwise, it will not work.需要一个 索引,否则将无法工作。 If you are using Android Studio, you'll find in the logcat an error message that looks like this:
如果您使用的是 Android Studio,您会在 logcat 中找到如下所示的错误消息:
FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/...
The required query can be created either directly in the Firebase Console , or by clicking on that link.所需的查询可以直接在Firebase 控制台中创建,也可以通过单击该链接来创建。 If the click doesn't work, simply copy and paste the URL into a web browser and your index will be created automatically for you.
如果点击不起作用,只需将 URL 复制并粘贴到 Web 浏览器中,就会自动为您创建索引。
If you choose the console, remember to set:如果选择控制台,记得设置:
Collection: Candidates Fields: registrationStatus ascending and voterID: ascending
集合:候选人字段:注册状态升序和选民ID:升序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.