[英]How to retrieve specific user from realtime Firebase in Android Studio
Hello I am currently doing an appointment chatting application between counsellors and user.您好,我目前正在做咨询师和用户之间的约会聊天应用程序。
The image is the screenshot of realtime Firebase.图像是实时 Firebase 的屏幕截图。 https://i.stack.imgur.com/kQG8x.png
https://i.stack.imgur.com/kQG8x.png
So i am trying to do chatting function after the counsellors accepted the booking appointment from the users.所以我在辅导员接受用户的预约后尝试做聊天功能。 However , in my case , it retrieve every counsellors information including counsellors that does not accept the booking.
但是,就我而言,它会检索所有辅导员信息,包括不接受预订的辅导员。 Screenshot of every counsellor appears in my list .
每个顾问的屏幕截图都出现在我的列表中。 I would like to only show "mary" because she is only who accept the appointment booking however according to the image , it shows mary and farah.
我想只显示“玛丽”,因为她是唯一接受预约的人,但是根据图片,它显示了玛丽和法拉。 I would be kindly appreciate if anyone could help me.
如果有人可以帮助我,我将不胜感激。 Thank you.
谢谢你。
The following is the code that display every counsellors.以下是显示每个辅导员的代码。
private void displayData(){
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Counsellors");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//mUsers.clear();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
Counsellors counsellor = snapshot.getValue(Counsellors.class);
if (counsellor!=null && counsellor.getId()!= null && !counsellor.getId().equals(firebaseUser.getUid())){
mUsers.add(counsellor);
}
userAdapter = new UserAdapter(getContext(),mUsers);
recyclerView.setAdapter(userAdapter);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
JSON snippets of my realtime Firebase ( Appointment, Counsellors , Users and Chat )我的实时 Firebase 的 JSON 片段(约会、辅导员、用户和聊天)
{ "Appointment" : { "-Mo69loW59iUHIMNfLOf" : { "date" : "11/26/21", "idDoctor" : "M8EUBl4vRubeW8iS92HiVIuY4rJ2", "idPatient" : "4WJh1MmoEfN4sqNaJrqbHhNFjxr1", "status" : "Accepted", "time" : "16:06" } }, "Chat" : { "-Mo6A8oY1Kt_ni71IlGN" : { "message" : "helo ", "receiver" : "4WJh1MmoEfN4sqNaJrqbHhNFjxr1", "sender" : "M8EUBl4vRubeW8iS92HiVIuY4rJ2" } }, "Counsellors" : { "M8EUBl4vRubeW8iS92HiVIuY4rJ2" : { "email" : "mary@gmail.com", "id" : "M8EUBl4vRubeW8iS92HiVIuY4rJ2", "name" : "mary", "specialist" : "family mental health" }, "v5FgbL4GuLeOE9ySVe7tgVFEk5D2" : { "email" : "farah24@gmail.com", "id" : "v5FgbL4GuLeOE9ySVe7tgVFEk5D2", "name" : "farah", "specialist" : "anxiety" } }, "Users" : { "4WJh1MmoEfN4sqNaJrqbHhNFjxr1" : { "email" : "jett24@gmail.com", "id" : "4WJh1MmoEfN4sqNaJrqbHhNFjxr1", "matric" : "BI18110293", "name" : "jett" } } }
first of all from my experience with Firebase, I will recommend you to migrate all your data from a real-time database to the Firestore database.首先,根据我使用 Firebase 的经验,我建议您将所有数据从实时数据库迁移到 Firestore 数据库。 Real-time to use only for chatting purposes.
实时仅用于聊天目的。
Here is the documentation for the difference between these two databases: RTDB vs Firestore这是这两个数据库之间区别的文档: RTDB vs Firestore
The second thing is if you need help, please post code snippets to see if there is something wrong with the code.第二件事是如果您需要帮助,请发布代码片段以查看代码是否有问题。 From the text, we cannot help you make fixes in your project.
从文本中,我们无法帮助您在项目中进行修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.