Question

I got a AutoCompleteTextView which gets linked to a standard SimpleAdapter. The adapter loads autocomplete values from a ArrayList<Map<String,String>> called CITIES.

Now, what happens is that when I start typing the AutoCompleteTextView correctly shows me all the entries which include the part of text I already wrote. But what I'd like to get is to see on top of the dropdown list all the items which start with the text I wrote and, after that, all the other items in, say, A-Z order. This is because if you're looking for hotels in Venice you want for sure to see VENICE at the top of the list.

enter image description here

I know this is mainly a data problem and we should not retrieve city names in such a ugly fashion, but this is what we do have now. So my question is: is there any way to tell the AutoCompleteTextView in which order it should show the items in the dropdown list?

Thank you

Was it helpful?

Solution

You will have to write a custom sorting function in Android. That way you can control the way elements are sorted inside of a list. See this answer to see how to write a custom sorting function: Android java custom sorting using Comparable

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top