'How to filter data by orderByChild()? [duplicate]
I want to filter data and put it into recyclerview accroding to it's category . And any Item can have multiple category.
My firebase hierarchy follows

My code is
private void processFilter() {
ArrayList<Items_modal_for_adp> list2=new ArrayList<>();
ArrayList<Items_modal_for_adp> listKey2=new ArrayList<>();
database.getReference().child("Items").orderByChild("Cat").equalTo("Fitness").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
list2.clear();
for(DataSnapshot snapshot1 : snapshot.getChildren())
{
Items_modal_for_adp adp=snapshot1.getValue(Items_modal_for_adp.class);
list2.add(adp);
}
listKey2.clear();
for(DataSnapshot snapshot2 : snapshot.getChildren())
{
Items_modal_for_adp adp=new Items_modal_for_adp(snapshot2.getKey());
listKey2.add(adp);
}
adapters.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
adapters=new itemAdapters(list2,listKey2,getContext());
binding.recyclerUser.setAdapter(adapters);
}
I don't have a good knowledge of " orderByChild()" and how it works.
Can anyone clear my doubt?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
