This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Android and the fly likes Custom AutoCompleteTextView behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Custom AutoCompleteTextView behavior" Watch "Custom AutoCompleteTextView behavior" New topic
Author

Custom AutoCompleteTextView behavior

Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Out of the box, the AutoCompleteTextView widget does not seem to be able to match the input string in the middle of a list value - the matches are always made at the beginning; e.g., entering "ar" matches "argentina", but not "hungary". I've found hints on how to extend the class (like this one), but they address a different sort of issue.

Matching in the middle of a string seems to require a Filter class with a custom performFiltering method - but ListAdapter only allows to get an existing Filter, not to set a custom one. I think this should be doable; anyone know what I'm missing?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
I figured it out. For the benefit of whoever may see this topic: The solution is to extend ArrayAdapter so that the getFilter method can return a custom Filter implementation with the intended match behavior. getCount and getItem(int) also need to be overridden.
 
Don't get me started about those stupid light bulbs.
 
subject: Custom AutoCompleteTextView behavior