Reputation: 3
I have stored data into the firebase real time database, but unable to retrieve a set of data from the database.. below i have attached a pic which shows the skeleton of my firebase database
Tell me how i will retrieve status data from database..
Sorry i changed my database structure like below..
Upvotes: 0
Views: 986
Reputation: 1
Assuming that the screen-shot is coorect and the structure is Firebase-root -> messages -> status
, please use the following code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference statusRef = rootRef.child("status");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String status = ds.getValue(String.class);
Log.d("TAG", status);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
statusRef.addListenerForSingleValueEvent(eventListener);
Upvotes: 1