Question

Does anyone know if it's possible to have the adapter for an AutoCompleteTextView search a different field then what it returns to the text view to be inserted?

For example, I have a string that contains a phone number, an address, and a name. This works good for searching because I can enter any of those values to get what I want, but I only want the full name to be returned back to the TextView to be displayed?

Is this possible or does the adapter have to use the same value for both searching and returning to the AutoCompleteTextView?

Hope this makes sense, thanks for reading, Tony

Was it helpful?

Solution

For what it's worth: I think another, possibly cleaner, option would be to set an OnItemClickListener on the AutoCompleteTextView. In the callback, you can call setText on the AutoCompleteTextView, passing in whatever string you wish to appear in the view.

This gives you the advantage that the callback indicates which item was selected (e.g., the row in the cursor result list.) Otherwise, it seems to me that you need to do a search of some kind just to find the information associated with the string that gets passed in to replaceText.

OTHER TIPS

This was much simpler than I thought it would be.

All you need to do is subclass either AutoCompleteTextView or MultiAutoCompleteTextView and override the replaceText method.

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