0

I am new to firebase and android. I am populating a listview with data from firebase using firebase List adapter. I understand that we can not chain filters in firebase.

Below is the code snippet from the activity. I created a firebase reference. Then I applied the equalTo filter to get items with category=clothes.

Query orderedActiveUserListsRef;

Firebase activeListsRef = new Firebase(Constants.FIREBASE_URL_USER_LISTS)
                    .child(mEncodedEmail);

orderedActiveUserListsRef = activeListsRef.orderByChild("category").equalTo("clothes");

I would like to further filter out results from orderedActiveUserListsRef before supplying it to the adapter.

One approach I found is creating an array by iterating the orderedActiveUserListsRef using the below code:

orderedActiveUserListsRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) {
            String category = (String) messageSnapshot.child("category").getValue();
            Log.d("CatList",category);
        }
    }

    @Override
    public void onCancelled(FirebaseError firebaseError) { }
});

Please advise the best possible approach. PS: I have denormalised the data.

tahaasadullah
  • 67
  • 1
  • 5

0 Answers0