问题
I have an AutoCompleteTextView
, and it works nicely, until I add a space to my input. If I had, say, a list of many historical events (Battle of Britain (1940), Battle of the Bulge (1944), [insert lots of battles], Napoleon's fatal march (1812), [insert lots other historical events]).
When I enter "Battle
" or "battle
", I get a list of all battles (although it seems there is a max), and when I enter "britain
", the "Battle of Britain (1940)"
appears in the results.
However, when I enter "1940"
, the list is empty, for the same reason that when I enter "itain"
I don't get any hits. I guess the space is some sort of separator or anchor. If I put 1940
in front of the String (like "1940 - Battle of Britain"
) and enter "19", I do get all the results starting with "19".
Is it possible to have the AutoCompleteTextView
autocomplete even when there's a character in front of the searched word/phrase/part? (So when I enter "1940", "Battle of Britain (1940)" will be amongst the results?)
回答1:
Use a custom Adapter
which implements Filterable, in the getFilter()
method .
Use String.contains()
for your requirement
来源:https://stackoverflow.com/questions/13027261/autocompletetextview-search-part-of-word-instead-of-full-word