Advertisements

RT DB Reading Multiple Child nodes

        //Reading User Object from Firebase Realtime Database
        myRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for (DataSnapshot data : dataSnapshot.getChildren()) {
                    //Getting User object from dataSnapshot
                    User user = data.getValue(User.class);
                    String username = user.getUserName();
                    String firstName = user.getFirstName();
                    String lastName = user.getLastName();
                    Date dob = user.getDob();
                    String day = dob.getDay();
                    String month = dob.getMonth();
                    String year = dob.getYear();

                    Log.i(TAG, "onDataChange: " + username);
                }


            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

                Log.i(TAG, "onCancelled: Error: " + databaseError.getMessage());

            }
        });