Reputation: 1399
I can check if any data that is a child of my reference has changed no problem but I cant find a way to check if a certain field has changed within that child.
Here is some code the .child("job") does not work as job is the field. It was just somethin I was trying.
Firebase ref = new Firebase(Config.FIREBASE_URL);
//adding a value event listener so if data in database changes it does in textview also not needed at the minute
ref.child("Driver").child("Driver2").child("job").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Toast.makeText(ProfileActivity.this, "YEAAA ", Toast.LENGTH_SHORT).show();
}
}
/************had to implement this method****************/
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
here is the json from the database
"Driver" : {
"Driver1" : {
"job" : "none",
"lat" : 53.4013419,
"lon" : -111.803055,
"name" : "JOHNNY"
},
"Driver2" : {
"job" : "job",
"lat" : 53.4012956,
"lon" : -6.4091191,
"name" : "MICK"
},
"Driver3" : {
"job" : "cccc",
"lat" : 45.815399,
"lon" : 15.966568,
"name" : "Boris"
}
}
I want to check if the job field changes, as the coordinates fields will be constantly changing anyway.
Upvotes: 5
Views: 3380
Reputation: 138814
You are using correctly addValueEventListener()
on the reference
but you don't need that for loop
. Your DataSnapshot
is already on the job child
, in which the key is job
and the value is: none
. So you need to remove the iteration. Hope it helps.
Upvotes: 7