I am sending "Appetizers and Snacks" which is in name
key from one activity 1 to activity 2.
In activity 2,the data received is simply :
Instead of this:
databaseReference = FirebaseDatabase.getInstance().getReference("All Categories").child("name").orderByValue().equalTo(received_id).getRef();
You'll want to use:
Query query = FirebaseDatabase.getInstance().getReference("All Categories").orderByChild("name").equalTo(received_id);
So:
orderByChild("name")
to tell the database to order all child nodes on the value of their name
property.equalTo(...)
to then filter down the sorted data.getRef()
as that actually undoes all your query buildin.To then read the data, do:
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot categorySnapshot: dataSnapshot.getChildren()) {
for (DataSnapshot recipeSnapshot: categorySnapshot.child("recipes").getChildren()) {
DetailModel p = recipeSnapshot.getValue(DetailModel.class);
detailModelList.add(p);
}
}
detailAdapter = new DetailAdapter(DetailCategory.this, detailModelList);
recyclerView.setAdapter(detailAdapter);
progressBar.setVisibility(View.INVISIBLE);
} else {
Toast.makeText(DetailCategory.this, "No data available !", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}
}
So:
recipes
of each node we get back in the snapshot.