in my firebase database I would like to check whether the "read" key is equalled to "false" However, the if statement below does not seem to work.
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String true3 = "true";
for(DataSnapshot ds : dataSnapshot.getChildren()) {
if( ( ds.child("read").getValue() == ("false"))){
ds.child("read").getRef().setValue(true3);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
q.addListenerForSingleValueEvent(eventListener);
ds.child("read").getValue()
will return an Object
and obj == "false"
will compare reference not their values so use snapshot#getValue(ClassName.class)
if(ds.child("read").getValue(String.class).equals("false")){
// and always compare String objects with String#equals
instead of
if( ( ds.child("read").getValue() == ("false"))){