1
databaseReference.child("List").orderByChild("Country")
                               .equalTo("US")
                               .addListenerForSingleValueEvent(new ValueEventListener() {

It work OK if the country value only is "US".

But if country value have more than a word: "US UK" it doesn't show this value, how can I search the value "US" in this case ?

Thanks for your help !!

AL.
  • 36,815
  • 10
  • 142
  • 281
  • The Firebase Database does not support queries with *contains* or regular expressions. See my list of related answered here: https://stackoverflow.com/questions/39606627/firebase-app-search-feature-query-using-string-regex#comment66522784_39606627 – Frank van Puffelen Jun 15 '17 at 14:23
  • What you're trying to do looks like a categorization of items. In that case it typically helps to create a inverted index, mapping each category to the items matching that category. Have a look at my answer here: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jun 15 '17 at 14:24

1 Answers1

1

This is not good way, but try it.

 databaseReference.child("List")
           .orderByChild("Country")
           .addListenerForSingleValueEvent(new ValueEventListener(Child data){
              if (data.value().Country.equals("US UK") {
                 databaseReference.child("List").child(data.key).addListenerForSingleValueEvent.....
              }
           })

Anyway, I'll try another way and give you a better answer later.

  • Maybe I wrong in code, (ex: data.value().getCountry() instead of data.value().Country ) but please understand how it work. And nice too meet you, Vietnamese. – Mạnh Hoàng Huynh Jun 15 '17 at 08:06