我有一个 AutoCompleteTextView
,以及它工作得很好,直到我添加了一个空间,我的输入。如果我有,说,许多历史事件的列表(不列颠之战(1940年),突出部(1944年)之战,[插入大量的战斗],拿破仑的死亡行军(1812),[插入其他很多历史事件])
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]).
当我输入战
或战
,我得到的所有战斗的列表(尽管它似乎有一个最大值),当我输入英国
,在不列颠之战(1940年)
出现在结果中。
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.
然而,当我进入1940年
,该列表是空的,出于同样的原因,当我进入itain
我没有得到任何命中。我猜想的空间某种分离器或锚。如果我把 1940年
在字符串前面(如1940年 - 不列颠之战
),然后输入19 ,我的不的让所有的结果,从19。
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".
是否有可能有 AutoCompleteTextView
自动完成,即使有一个在搜索词/短语/部分的前面的字符? (所以当我输入1940年,不列颠之战(1940年)将是其中的结果?)
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?)
使用自定义的适配器
它实现的可筛选,在用getFilter()
方法。
检查这个的链接,使用字符串。包括()
为您的要求。
Use a custom Adapter
which implements Filterable, in the getFilter()
method .
Check this link, Use String.contains()
for your requirement