Assuming that game1
, game2
and game3
nodes are direct children of your Firebase database root, to solve this, please use the following code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String team1 = ds.child("team1").getValue(String.class);
String team2 = ds.child("team2").getValue(String.class);
if(team1.equals("redsox") && team2.equals("yankees")) {
Log.d("TAG", "Foaund only: team1:redsox and team2:yankees");
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
rootRef.addListenerForSingleValueEvent(valueEventListener);
But note, team1 in game1 is red sox
(two words) and in the game2 is redsox
(single word). In order to make the equals()
method work, both properties should hold the same value, either red sox
or redsox
.