Code in Kotlin
val afill = findViewById<AutoCompleteTextView>(R.id.myTextId)
var showAFill = false
afill.addTextChangedListener (object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
showAFill = afill.isPopupShowing
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int)
}
})
afill.onItemClickListener = object : AdapterView.OnItemClickListener {
override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
showAFill = false
}
}
, .
showAutofill.setOnClickListener { _ ->
if (showAFill) afill.dismissDropDown()
else afill.showDropDown()
showAFill = !showAFill
}
showAutofill -