Development issue/problem:

I want my EditText to work like an AutoComplete, so I write in an 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 have a simple EditText and a button called Search. So, if we type a place name in EditText and click the Search button, it means it should go to that place on the map.
So I want EditText to work like AutoComplete.
How can I do that?

How can I solve this problem?

Solution 1:

Just use AutoCompleteTextView instead of the normal EditText.

The Hi-Autocomplete function will be useful.

EDIT: The above link seems to have expired. The new site is here: https://developer.android.com/training/keyboard-input/style#AutoComplete.

Solution 2:

First convert your EditText->AutoCompleteTextView

Next, connect your XML file to AutoCompleteTextView via the ArrayAdapter.

Assuming that the array of XML strings you created is named list_of_countries, you can link it to your AutoCompleteTextView as follows:

String[] countries = getResources().getStringArray(R.array.list_of_countries) ;
ArrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,countries) ;
actv.setAdapter(adapter) ;

Solution 3:

I use this code:

android how an EditText work as AutoComplete –

1) In AndroidManifest.xml

2) For xml layouts, use AutoCompleteTextView instead of EditText.

3) Use it in the activity file

private ArrayAdapter getEmailAddressAdapter(Context context) [
Account[] accounts = AccountManager.get(context).getAccounts() ;
String[] addresses = new String [accounts.length] ;
for (int i = 0 ; i (context, android.R.layout.simple_dropdown_item_1line, addresses) ;
}

4) For creative activities :

AutoCompleteTextView autoCompleteTextView1 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1) ;
autoCompleteTextView1.setAdapter(getEmailAddressAdapter(this) ) ;

Solution 4:

By default, the ArrayAdapter filters only on the first characters. If you also want to see the words that contain the keyword, you must use a custom ArrayAdapter and override the getView and getFilter methods. See the complete solution I provided in another StackOverflow question: https://stackoverflow.com/a/37298258/1808829

A piece of code:

The public class AutoSuggestAdapter extends ArrayAdapter
{
@overview
public view getView(int position, View convertView, ViewGroup parent)
{
// handle view here
}

@Override
public Filter getFilter()
{
// implement filtering here
}
}

Solution no. 5:

This code is used to change the settings of MultiAutoCompleteTextView

ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,codeKeyWords);
MultiAutoCompleteTextView autoCompleteTextView1 = (MultiAutoCompleteTextView) findViewById(R.)).id.autoCompleteTextView1);
autoCompleteTextView1.setAdapter(adapter);
autoCompleteTextView1.setThreshold(1);
autoCompleteTextView1.setTokenizer(new this.CommaTokenizer()) ;

And here is this code to separate words with a space and n characters…. (Why do we need this code? Because Normal multiAutoComplete.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); so, and it separates words into ‘,’ characters, but our code will help you to separate words into ‘ and ‘n’ characters).

/**
* This simple tokenizer can be used for lists of
* items separated by a comma and one or more spaces.
*/
public static class CommaTokenizer implements Tokenizer {
public int findTokenStart(charSequence text, cursor int) {
int i = cursor ;

while (i > 0 && text.charAt(i – 1) != ‘ ‘) {i–;} while (i 0 && text.charAt(i – 1) == ”) {i–;}

if (i > 0 && text.charAt(i – 1) == ‘ ‘) {
return text;
} else {
if (text instance of Spanned) {
SpannableString sp = new SpannableString(text + n);
TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
Object.class, sp, 0);
return sp;
} else {
return text +;
}
}
}

Good luck!

 multiautocompletetextviewauto text complete textview androidautocompletetextview android kotlinandroid autocompletetextview dropdown styleautocompletetextview onitemselectedlistenerandroid autocompletetextview custom adapterautocomplete edittext android githubandroid studio auto complete shortcutturn on autocomplete androidandroid edittext suggestionshow to copy paste in android studiohow to copy text from edittext in androidautocompletetextview with api call androidandroid autocompletetextview stackoverflowautocompletetextview with listview in androidautocompletetextview text change listenerautocompletetextview get selected item kotlinedittext autofill hintsautocompletetextview not showing dropdownautocompletetextview kotlinandroid data binding autocompletetextviewkotlin autocompleteautocompletetextview custom adapter kotlinappcompatautocompletetextview adapter kotlin

You May Also Like

Top 5 best crotorrents alternatives for free game torrents (Safe&working) – Torrent

Crotorrents is a site where you can download and play video games…

Cybersecurity Basics: How To Pick A Good VPN

How to choose a good VPN? This is one of the questions…

11 Best Video Games We Forgot To Play In 2020

In a strange, disturbing and sometimes downright scary year, video games have…

How To Use a Laptop as a Monitor For PS4 with HDMI – 2020 Guide

For many avid gamers, PlayStation is one of the best gaming devices.…