AutoCompleteTextView search part of word instead of full word

不羁的心 提交于 2019-11-30 17:22:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!