Out of the box, the AutoCompleteTextView widget does not seem to be able to match the input string in the middle of a list value – the matches are always made at the beginning; e.g., entering “ar” matches “argentina“, but not “hungary“.
How can I search for the text in the middle of the word ? Can anyone give me an idea ?
Thanks in advance !
You would need to write a custom
Filterclass and implement theperformFilteringmethod yourself. This method takes aCharSequenceargument, which you can use to perform whatever String operations you need in order to generate a list of matches from your dataset (in your case, you could useString.containsinstead ofString.startsWith). TheperformFilteringfunction is not run on the UI thread.You then return your list of matches as a
FilterResultsobject, which contains anObjectvalues (your list of matches, probably anArrayList) and anintcount which is the size of your list of matches.Finally, implement the
publishResultscallback method, which returns once the worker thread has generated the list of matches, allowing you to callnotifyDataSetChangedon your AutoCompleteTextView’s adapter so that it can display the results.