As in my table user having the same profession=doctor.
I want to select all users having the same profession and want to show them in recycler view.
As in my table user having the same profession=doctor.
I want to select all users having the same profession and want to show them in recycler view.
To be able to get all the users that a profession set as a doctor, you need to see a Query. So please use the following lines of code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("users");
Query queryByProffesion = usersRef.orderByChild("proffesion").equalTo("doctor");
queryByProffesion.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
@Override
public void onComplete(@NonNull Task<DataSnapshot> task) {
if (task.isSuccessful()) {
for (DataSnapshot ds : task.getResult().getChildren()) {
String name = ds.child("name").getValue(String.class);
Log.d(TAG, name);
}
} else {
Log.d(TAG, task.getException().getMessage()); //Don't ignore potential errors!
}
}
});
The result in the logcat will be the name of all users who are doctors. For displaying the results in a RecyclerView, please check my answer from the following post: