Using a custom list adapter with the AutoCompleteTextView and still keeping the functionality of the auto complete working the same
So say I use the following adapter for the AutoCompleteTextView:
public class RosterAdapter extends ArrayAdapter<Player> {
...
}
That's using an object called Player, where as the default AutoCompleteTextView works with a String.
The list displays fine when I use the custom one, but the only issue I have is when I start typing something, it doesn't display the right things.
For example - if I start typing bo
, I would expect people with the name Bob Henderson
, Garry Bobrinski
, etc..
But what comes up is the same l开发者_运维技巧ist, which doesn't seem to matter what I type - just randomly comes up.
Can I not use a custom object for this to work? Do I have to use a String for it to match the entries properly? Or is there someway I can tell it to look at a specific string for each of the entries?
* Update *
Here's some more code - this is how I set the custom adapter RosterAdapter
. This works, but the autocomplete aspect of it doesn't function properly. It's almost like it gets confused and doesn't know what to look for in the object, to match the typed string.
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_players);
RosterAdapter adapter = new RosterAdapter(RosterActivity.this, R.layout.roster_row, players);
textView.setAdapter(adapter);
This is using a generic ArrayAdapter, and this works fine for matching the entries:
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_players);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(RosterActivity.this, R.layout.players_autocomplete, players);
textView.setAdapter(adapter);
It's hard to say for sure without any code, but I believe you might not be implementing getFilter()
for your to let the adapter use the Player
objects as strings.
For an example (unrelated requirement, but same filter needed), see: How do I Use AutoCompleteTextView and populate it with data from a web API?
There's another example here: http://www.sacoskun.com/2008/08/autocompletetextview-with-simpleadapter.html
精彩评论