0

i use recyclerview to retrieve a chat messages and i am wondering if there is method to retrieve two different values i mean something like this :

FirebaseRecyclerOptions<enchat> options = 
    new FirebaseRecyclerOptions.Builder<enchat>()
        .setQuery(
            mChatDatabase.orderByChild("state").equalTo("sent")
            && mChatDatabase.orderByChild("state").equalTo("received"),
         enchat.class)
        .build();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Habib
  • 27
  • 6

1 Answers1

1

There is no way to pass two values into a condition. Firebase Realtime Database doesn't support this type of OR condition.

Also see:

The common workarounds are:

  • Perform two queries and merge the results in your application code. But you won't be able to use the adapters from FirebaseUI as is in that case.

  • Perform a range query, but this only works if there are no state values between received and sent. If that is the case, the query could be:

    mChatDatabase.orderByChild("state").startAt("received").endAt("sent")
    
  • Add an additional property that is true when the state is either received or sent and filter on that:

    mChatDatabase.orderByChild("stateIsReceivedOrSent").equalTo(true)
    
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807