AutoCompleteTextView searches for a part of a word instead of a full word

I have an AutoCompleteTextView and it works fine until I add a space to my input. If I had, say, a list of many historical events (the battle for Britain (1940), the battle for the bulge (1944), [insert many battles], the fatal march of Napoleon (1812), [insert many other historical events]).

When I enter β€œ Battle ” or β€œ Battle ” I get a list of all the battles (although it seems that there is a max), and when I enter β€œ britain ”, "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 "1940" "itain" I do not receive any hits. I assume this is some kind of separator or anchor. If I put 1940 in front of the line (for example, "1940 - Battle of Britain" ) and enter β€œ19”, I get all the results, starting with β€œ19”.

Is it possible to have AutoCompleteTextView autocomplete even if there is a character before the searched word / phrase / part? (So, when I enter β€œ1940”, β€œthe battle for Britain (1940)” will be among the results?)

+4
source share
1 answer

Use a custom Adapter that implements Filterable in the getFilter() method. Use String.contains() for your requirement

+5
source

Source: https://habr.com/ru/post/1441501/


All Articles