[Android] AutoCompleteTextView not showing suggestions in Kotlin

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:

autoCompleteTextView?.apply {
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

autoCompleteTextView?.apply {
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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s