How to apply filters by name and price on list fetched from firebase android

Viewed 39

i am new to android and i am working on my Practice app in which i am using firebase realtimeDatabase. I have stored some data on the DB and i am getting it in List, which is working fine but there is some problem that i want to apply Filters on my list with Price and Name of the items present in the list. I am unable to do that. i am using Material Chips buttons to apply filters. i tried some github topics to do this but couldn't do that. Kindly give me some guidelines so that i can do this sorting.

1 Answers

Try something like this-

String name = "Pen";
Integer price = 100;

CollectionReference productRef = firebaseFirestore.collection("products");
productRef.whereEqualTo("name", name).whereGreaterThanOrEqualTo("price",price).orderBy("name", Direction.ASCENDING).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
    @Override
    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

    }
});

for more such queries with firestore check this- https://firebase.google.com/docs/firestore/query-data/queries#java

Related