How To Retrieve Value From The Highest/last Level Node Using 'childeventlistener' From Firebase?
Solution 1:
I think that you are doing your query in the wrong way. onChildAdded
method is retrieving you each child of a specific value (userID2 I suppose). If that is what you want, then just use a onValueEventListener()
to retrieve the whole dataSnapshot of your userId2 node each time that it changes.
If you want to retrieve the data just once, you should use onSingleValueEventListener()
. And OnChildEvent()
is used to retrieve lists of data where you want to track each of the child individually. For example if you attach an OnChildEventListener
to mReference.child(rID)
you will get a OnChildAdded
for each userId, what is pretty usefull like for example fill a RecyclerView
or a ListView
being able to update each item individually together with your Firebase Data.
If i'm not wrong what you want is just get updates of your userId2
reference, in that case attach a OnValueEventListener
to that reference and you will get a call each time a value is modified, deleted, or added.
firebaseDatabaseRef.addValueEventListener(newValueEventListener() {
@OverridepublicvoidonDataChange(DataSnapshot dataSnapshot) {
customPOJO customPOJO = dataSnapshot.getValue(YourCustomPOJO.class);
customPOJO.getName();
customPOJO.getEmail();
customPOJO.getfavoriteFood();
//and so on....
}
@OverridepublicvoidonCancelled(DatabaseError databaseError) {
}
});
Post a Comment for "How To Retrieve Value From The Highest/last Level Node Using 'childeventlistener' From Firebase?"