答案 0 :(得分:2)
这样的事情可以解决问题:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("users");
ref.orderByChild("name").equalTo("Yash Mehta").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
System.out.println(userSnapshot.getKey());
System.out.println(userSnapshot.child("Name").getValue(String.class));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException();
}
});
答案 1 :(得分:0)
您正在寻找以下内容。
这是示例搜索名称
refDatabase.child("users").orderByChild("user2key").orderByChild("name").equalTo("search here word").addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//data will be available on dataSnapshot.getValue();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "getUser:onCancelled", databaseError.toException());
}
});
如果不符合要求,请尝试以下
How to search for a value in firebase Android