I use AutoCompleteTextView in my project.
XML:
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textfield"
android:hint="Search..."/>
Kotlin:
val autocompleteOptions = ["France Paris", "UK London", "UK York", "Sydney Australia", "Vien Austria", "Tokyo Japan", "Kiev Ukrain", "Tallinn Estonia"]
// Initialize a new array adapter object
val arrayAdapter = context?.let {
ArrayAdapter<String>(
it, // Context
android.R.layout.simple_list_item_1,
autocompleteOptions // Array
)
}
// Set the AutoCompleteTextView adapter
autoCompleteTextView.setAdapter(arrayAdapter)
The problem here is that when I add white space in the autocomplete text field during the search the dropdown disappears.
It looks like the search does not recognize the white space character as part of the searched string.
For example, if I start to print in autocomplete text field "UK" I will get two options in autocomplete dropdown "UK London" and "UK York", when I continue to print and add white space the autocomplete dropdown disappears.
I question how to prevent the disappearance of autocomplete dropdown when white space is added during the search.