I want to fetch values related to a particular key from the data received in my snapshot
. This is my code:
dbref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot child : snapshot.getChildren()) {
Log.d("output",child.getValue().toString());
}
})
My output
is like this:
{"name"="abc", "age"=23, "height"="156 cm"}
I want to fetch the value with the key height
. How do I do that?
3
Answers
The child variable must have a getHeight() method inside it. Try like this. 🙂
This is my usually way when i get data from firebase.
First, create a class for store data, ex
Then when you getting a snapshot
Getting the value of the grandchild with the key
height
of the parent solved the issue: