I'm working on the android app and I have a problem when trying to read products data from firebase. I need these product name, product price and product description data to use in recycler view.
When I tried to run the code I didn't get this data.
I tried the given code:
ProductsRef = FirebaseDatabase.getInstance().getReference().child("Products");
ProductsRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
productItems = getAllItems(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w( "Failed to read value.", error.toException());
}
});
public ArrayList<Products> getAllItems(DataSnapshot dataSnapshot){
items = new ArrayList<Products>();
for (DataSnapshot item : dataSnapshot.getChildren()) {
items.add(new Products(
item.child("category").getValue().toString(),
item.child("description").getValue().toString(),
item.child("date").getValue().toString(),
item.child("image").getValue().toString(),
item.child("pid").getValue().toString(),
item.child("pname").getValue().toString(),
item.child("price").getValue().toString(),
item.child("time").getValue().toString()
));
}
return items;
}