What I am trying to do is to populate a listview with all the child from /ItemRequest from both admin and user.
To solve this, you need to iterate over the DataSnapshot
object twice, like in the following lines of code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference itemRequestRef = rootRef.child("ItemRequest");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot dSnapshot : dataSnapshot.getChildren()) {
for(DataSnapshot ds : dSnapshot.getChildren()) {
String productName = ds.child("ProductName").getValue(String.class);
Log.d(TAG, productName);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
}
};
itemRequestRef.addListenerForSingleValueEvent(valueEventListener);
The output in your logcat will be:
Manix
Manix
Manix
If you want to display those results in a ListView
, please see my answer from this post: