0
teamapp-25ba7
  schedules
    -LHc3zKZhNFLq536dpA1
      UID:    
      date:
      details:
      time:
      title:
    -LHc7MBAoNwLWCNgkZ_y
      UID:
      date:
      details:
      time:
      title: 

from the above example of my nodes, i would like to just get details and time values ,my question is how do i retrieve just those 2 values . i tried iterating through all the values but that just gets me everything

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Bryan Toromo
  • 141
  • 7
  • Please edit your question to show what you've already tried. Without that it is unlikely we'll do a better job explaining what to do than the Firebase documentation: https://firebase.google.com/docs/database/android/lists-of-data – Frank van Puffelen Aug 15 '18 at 08:46
  • If you're asking whether it's possible to load a subset of all properties of each node, the answer is no. The Firebase Database always reads complete nodes. – Frank van Puffelen Aug 15 '18 at 08:46

1 Answers1

1

Assuming that you want to get the values of details and time properties from all objects and also assuming that the details property is of type String and the time is ServerValue.TIMESTAMP, to solve this please use the following code:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference schedulesRef = rootRef.child("schedules");
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String details = ds.child("details").getValue(String.class);
            long time = ds.child("time").getValue(Long.class);
            Log.d("TAG", details + " / " + time);
        }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {}
};
schedulesRef.addListenerForSingleValueEvent(valueEventListener);
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193