0

I have an AutoCompleteTextView which I am trying to populate from an adapter created from values stored in Firebase. The id of the AutoCompleteTextView is medicineName Here is my code

    val adapter = ArrayAdapter<String>(this,android.R.layout.simple_list_item_1)
    mRef = FirebaseDatabase.getInstance().reference.child("Medicines")

    mRef.addValueEventListener(object: ValueEventListener {
        override fun onDataChange(dataSnapshot:DataSnapshot) {
            for (suggestionSnapshot in dataSnapshot.children)
            {
                val suggestion = suggestionSnapshot.child("Name").getValue(String::class.java)
                adapter.add(suggestion)
            }
        }
        override fun onCancelled(databaseError:DatabaseError) {
        }
    })
    medicineName.setAdapter(adapter)
    medicineName.setOnFocusChangeListener { _, b ->
        if(b) medicineName.showDropDown()
    }

However, the AutoCompleteTextView does not populate with this. The structure of the Firebase data is as follows:

enter image description here

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
oTwo
  • 185
  • 2
  • 13
  • I checked the same. The list of medicines is pretty long. Around 20K data points. It seems medicineName.setAdapter(adapter) is called before the for loop is complete. Hence the list remains empty – oTwo Jun 12 '19 at 19:51
  • See also [Firebase-UI](https://github.com/firebase/FirebaseUI-Android) – Kato Jun 12 '19 at 23:54

0 Answers0