How To Fetch User Id To Perform A Display List In Android Studio For Admin To View The Order List?
I want to display a customer order list inside my admin page. But it gives me blank page with no error inside the logcat. Below is my database: I want to display the Order inside
Solution 1:
Your data structure seems to be:
Orders: {
uid1: {
orderid1: { ... },
orderid3: { ... }
},
uid2: {
orderid2: { ... },
orderid4: { ... }
}
}
So you have two dynamic levels under Orders
: one for the UID, and one for the order IDs. Since you're listening for the data under all of Orders
, your onDataChange
will need to contain a separate loop for each of these dynamic levels.
Right now you have one loop, which means that your ds
refers to the data for a user, while you're then trying to read a order from it. Please use better variable names in the future, as it can help you find problems like this much more easily.
The correct approach is to first loop over the users, and then inside that loop over the orders for that user.
Something like:
databaseReference = FirebaseDatabase.getInstance().getReference("Order");
databaseReference.addValueEventListener(newValueEventListener() {
@OverridepublicvoidonDataChange(@NonNull DataSnapshot dataSnapshot) {
orderList = newArrayList<>();
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
for (DataSnapshot orderSnapshot : userSnapshot.getChildren()) {
orderList.add(orderSnapshot.getValue(Order.class));
}
}
psOrderAdapterPsOrderAdapter=newpsOrderAdapter(orderList);
recyclerView.setAdapter(PsOrderAdapter);
}
Post a Comment for "How To Fetch User Id To Perform A Display List In Android Studio For Admin To View The Order List?"