Fakhriddin Abdullaev
Fakhriddin Abdullaev

Reputation: 4920

Android Firebase: get all object inside child?

I have this firebase database enter image description here

How can I get Properties items?

this is how I try to read

for (DataSnapshot snap : dataSnapshot.getChildren()) {
                    User user = snap.getValue(User.class);

                    mPropertyList = snap.getValue(User.class).getProperty();

                    //if not current user, as we do not want to show ourselves then chat with ourselves lol
                    try {
                        mAllUserList.add(user);

                        if (mAuth.getCurrentUser().getEmail().equals(user.getEmail()))
                            if (user.getUser_type().equals("landlord")) {
                                user_rule = "landlord";
                                landUser = user;
                            }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

Upvotes: 0

Views: 398

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80924

To get the Properties items, try the following:

FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String userid=user.getUid();
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("Users").child(userid).child("properties");
usersRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
   for(DataSnapshot datas: dataSnapshot.getChildren()){
       String desc=datas.child("description").getValue().toString();
       String type=datas.child("type").getValue().toString();
      //get other items
 }
}
@Override
public void onCancelled(DatabaseError databaseError) {
 }
});

the snapshot is at properties after iterating you will be able to get the items there

Upvotes: 1

Related Questions