AutoCompleteTextView 搜索单词的一部分而不是完整的单词 [英] AutoCompleteTextView search part of word instead of full word
问题描述
我有一个 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]).
当我输入Battle
"或battle
"时,我会得到所有战斗的列表(虽然似乎有一个最大值),当我输入"britain
",结果中出现不列颠之战(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 - Battle of British"
)并输入19",我do得到所有结果以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?)
推荐答案
使用实现 Filterable,在 getFilter()
方法中.使用 String.contains()
满足您的要求
Use a custom Adapter
which implements Filterable, in the getFilter()
method .
Use String.contains()
for your requirement
这篇关于AutoCompleteTextView 搜索单词的一部分而不是完整的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!