Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android how an EditText work as AutoComplete

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?

like image 483
Jyosna Avatar asked Jun 27 '11 04:06

Jyosna


2 Answers

Just use an AutoCompleteTextView instead of normal EditText.

hello-autocomplete will be helpful.

EDIT: The above link looks like has expired. The new page is here: https://developer.android.com/training/keyboard-input/style#AutoComplete

like image 164
Arnab Chakraborty Avatar answered Oct 08 '22 12:10

Arnab Chakraborty


First convert your EditText->AutoCompleteTextView

Then link your XML file to the AutoCompleteTextView using a ArrayAdapter

Assume that the XML string-array you created is named as list_of_countries then it can be linked to your AutoCompleteTextView as follows:

String[] countries = getResources().getStringArray(R.array.list_of_countries); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries); actv.setAdapter(adapter); 
like image 20
Bestin John Avatar answered Oct 08 '22 12:10

Bestin John