Reputation: 775
I am trying to figure out a way to listen for a single item using the FireBase API's. So far I figured out how to query a single item using the orderByKey
and equalTo
functions.
I tried to do something similar for listening for a single value, but anytime I change one value it gives me the whole database items when I just want the one that was changed. I've added the valueEventListener
and the childEventListener
, but they seemed to do similar things.
Is there a way to listen for a single item and only return that single item?
Upvotes: 0
Views: 1327
Reputation: 33846
If I understand you correctly, lets assume this is your Firebase setup summary:
yourApp:
"node": {
"subNode1": {
"value1": value,
"value2": value,
"subSubNode":{
//....values....//
},
},
"node2": { ... },
"node3": { ... }
//...and so on ..//
},
And you are trying to listen to value2
? If that is the case, that is not possible. To access this, you need to listen to the parent node; subNode1
, and onChildEvent
, just get that value.
However, if you are trying to listen to subNode1
or even subSubNode
, that is possible. By just providing the path to this object when creating the Firebase object.
If you post more code, I will modify this accordingly to better answer your question.
Say you wanted to retrieve subSubNode
. Create a Firebase reference to that and add a listener:
Firebase firebase = new Firebase("yourFirebaseURL").child("node").child("subSubNode");
firebase.addChildEventListener(new .....);
Upvotes: 1