Reputation: 49
i have a problem in my android project which is connected to firebase. I want to display the child elements of my firebase database in a recyclerview. For this i created the following code to save the data in an arraylist. But there is a problem with attaching the childs of the path - the code does not add the items to the list :|. Is there an error in the reference to the database or an error in the eventlistener?
private void loadDataOutfitDetail(String userID, String weatherToday){
// set the firebase path for loading the images of the clothes
databaseRefOutfit = FirebaseDatabase.getInstance().getReference(userID + "/" + weather1 + "/ID1" + "/details");
// clear the list for showing only the filtered weather
uploadDetails.clear();
// get data out
databaseRefOutfit.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()){
UploadDetails upload = postSnapshot.getValue(UploadDetails.class);
// add items to list
uploadDetails.add(upload);
}
// update the recyclerview
outfitAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(getActivity(), databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
My Firebase database has the following structure:
USERID
outfit
weather1
ID1
details
desciption: Here is a description
name: MyName
imageUpperPart
name: image1
ID2
details
description: Here is another description
name: NewName
imageUpperPart
name: image2
How can I add the values of the details node to the arraylist uploadDetails?
Thank you keved :)
Upvotes: 1
Views: 916
Reputation: 80914
Change the reference to the following:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference(userID).child("outfit").child("weather1").child("ID1").child("details");
You are missing the node outfit
in your reference.
Upvotes: 2