问题
I want to match branch value in all child of student nodes with the value I already have and if matched successfully then I want to retrieve 'Student name' value in matched child see blow image
回答1:
You're looking for a query in that case.
To match the value of branch
and then print the value of studentName
for all matching child nodes, you'd do:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference(".../students");
Query query = ref.orderByChild("branch").equalTo("Electronics Engineering");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot studentSnapshot: dataSnapshot.getChildren()) {
Log.d(TAG, studentSnapshot.child("studentName").getValue(String.class));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
}
来源:https://stackoverflow.com/questions/60405198/firebase-get-specfic-chid-from-parent