It’s been a long time without posting 🙂 Today I’ll comment one of these stupid issues that make you waste several hours.
I was implementing an AutoCompleteTextView in my Android App, written in Kotlin. Given an arbitrary array of Strings (let’s say, country names), I was setting the adapter like this:
setAdapter(ArrayAdapter(context, android.R.layout.simple_expandable_list_item_1, R.array.countries))
Note the last parameter: It is not a string array, but a Resource ID*
All I had to do is to pass a String array instead of the ResourceId. So I resolved it like this
setAdapter(ArrayAdapter(context, android.R.layout.simple_expandable_list_item_1, resources.getStringArray(R.array.countries)))
I wasted several time discovering where the problem was!
Hope you find this useful 🙂
Have a nice coding day!
* Compiler does not complain about this because there is a consturctor for ArrayAdapter that accepts a resource ID as third parameter, but that’s the ID of the TextView containing the suggestion.