Reputation: 443
I have a predefined List<String>
. Now in my app I retrieved data from Firebase database. Generally I used:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child("Users").orderByChild("id").equalTo("string");
But for more stuff I want to filter data from my List<String>
. So is this possible like below query?
Query query = reference.child("Users").orderByChild("id").equalTo(***String_exists_in_predefined_list***);
Upvotes: 4
Views: 1282
Reputation: 1506
Get the string from your predefined list in oncreate. Call the method with your query and carry over the string and use it there.
Inside oncreate
String fromlist = [retrieve here];
queryData(fromlist);
Upvotes: 0
Reputation: 138824
So is this possible like below query ??
No, it's not possible. You cannot pass a list of strings as the second argument to the equalTo()
method because there is no such a method that accepts that. You need to iterate over the list and create a query for each one of those elements and merge the result client side.
Edit:
You need to loop through the list and create a query for each element:
for(String element : list) {
Query query = reference.child("Users").orderByChild("id").equalTo(element);
}
Upvotes: 1