I want my EditText
should work as AutoComplete
, for that I write in XML file
android:inputType="textAutoComplete|textAutoCorrect"
but it's not working.
I am working with API v2.2 and my Activity extends MapActivity
, there I put a simple EditText
and a button named "Search". so if we type the location name in EditText
and press search button means it should go to that location in map.
So I want that EditText
to work as a AutoComplete
.
How can I do that?
Just use an
AutoCompleteTextView
instead of normalEditText
.hello-autocomplete will be helpful.
This code for change settings of MultiAutoCompleteTextView
And below that code for make spliting words by space char and \n charactes.. (Why we need this code? Because Normal
multiAutoComplete.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
like that and it make spliting the words by ',' character, But our code help you to make that spliting by these characters ' ' and '\n' )I use this code:
1) On AndroidManifest.xml
2) On xml layout you must use AutoCompleteTextView instead of EditText.
3) Use this on Activity file
4) On onCreate activity:
First convert your
EditText->AutoCompleteTextView
Then link your XML file to the
AutoCompleteTextView
using aArrayAdapter
Assume that the XML
string-array
you created is named aslist_of_countries
then it can be linked to yourAutoCompleteTextView
as follows:Default
ArrayAdapter
filters only by the first characters. In case you want to see also words which contain the searching keyword, you need to use a custom ArrayAdapter and override itsgetView
andgetFilter
methods. Take a look at a complete solution I provided in another StackOverflow question: https://stackoverflow.com/a/37298258/1808829