I am new to Firebase and NoSQL. I have an Android Demo with the Autocomplete City text box in which I want to populate the cities that I have from my Firebase database as I type.
{ "cities":{ "Guayaquil":true, "Gualaceo":true, "Quito":true, "Quevedo":true, "Cuenca":true, "Loja":true, "Ibarra":true, "Manta":true } }
This is what I still have.
How can I get from DB cities that start with a letter (keyboard input)? If I start typing "G", I want to get "Guayaquil" and "Gualaceo".
If I use orderByValue , an empty snapshot is always returned.
If I use orderByKey , return the whole list.
Query citiesQuery = databaseRef.child("cities").startAt(input).orderByValue(); citiesQuery.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { List<String> cities = new ArrayList<String>(); for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) { cities.add(postSnapshot.getValue().toString()); }
Note. . If you can recommend a better data structure, please.
source share