AutoCompleteTextView &
MultiAutoCompleteView
1
Sourabh Sahu
AutoCompleteTextView
• In Android, AutoCompleteTextView is a view i.e similar
to EditText, except that it displays a list of completion
suggestions automatically while the user is typing.
• <AutoCompleteTextView
android:id="@+id/countryTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is an AutoCompleteTextView"/>
• AutoCompleteTextView simpleAutoCompleteTextView = (AutoCompleteTextView)
findViewById(R.id. countryTextView" );
• String AutoCompleteTextViewValue =
simpleAutoCompleteTextView.getText().toString();
Adapter
• ArrayAdapter(Context context, int resource, int
textViewResourceId, T[] objects)
• String[] countryNameList = {"India", "China",
"Australia", "New Zealand", "England",
"Pakistan"};
• AutoCompleteTextView simpleAutoCompleteTextView =
(AutoCompleteTextView) findViewById(R.id.countrytv);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, countryNameList);
simpleAutoCompleteTextView.setAdapter(adapter);
simpleAutoCompleteTextView.setThreshold(1);//start searching
from 1 character
simpleAutoCompleteTextView.setAdapter(adapter); //set the
adapter for displaying country name list
MultiAutoCompleteTextView
•  MultiAutoCompleteTextView is an 
editable TextView extends AutoCompleteTextView that can 
show the complete suggestion for the sub-string of a text 
allowing user to quickly select instead of typing whole. An 
AutoCompleteTextView only offers suggestion about the 
whole sentence and a MultiAutoCompleteTextView offers 
suggestion for every token in the sentence. We can specify 
what is the delimiter between tokens.
• <MultiAutoCompleteTextView android:id="@+id/andnames" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" android:text="This Is A 
MultiAutoCompleteTextView" />
• MultiAutoCompleteTextView 
and AutoCompleteTextView is that 
AutoCompleteTextView can hold or select 
only single value at single time but 
MultiAutoCompleteTextView can hold 
multiple string words value at single time. 
These all values are separated by 
comma(,).
• / initiate a MultiAutoCompleteTextView MultiAutoCompleteTextView 
simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) 
findViewById(R.id. andnames); String MultiAutoCompleteTextViewValue = 
simpleMultiAutoCompleteTextView.getText().toString(); // retrieve  a value from 
MultiAutoCompleteTextView
• setTokenizer(MultiAutoCompleteTextView.Tokenizer t):  This method sets the 
Tokenizer that will be used to determine the relevant range of the text where the 
user is typing. CommaTokenizer is used to set the tokenozer that distinguish the 
various substrings by comma.
• // initiate a 
• MultiAutoCompleteTextView MultiAutoCompleteTextView 
simpleMultiAutoCompleteTextView = (MultiAutoCompleteTextView) 
findViewById(R.id. andnames); // set tokenizer that distinguish the various 
substrings by comma simpleMultiAutoCompleteTextView.setTokenizer(new 
MultiAutoCompleteTextView.CommaTokenizer());
• setThreshold(int threshold):
• This method is used to set threshold value that help us to start
the searching from a specific character. In this we set int type
value used to specify the threshold . Suppose if set 1 value for
threshold then on the time of typing searching is start from first
character.
• // initiate a MultiAutoCompleteTextView
MultiAutoCompleteTextView simpleMultiAutoCompleteTextView =
(MultiAutoCompleteTextView)
findViewById(R.id.simpleMultiAutoCompleteTextView); // set
threshold value 2 that help us to start the searching from second
character simpleMultiAutoCompleteTextView.setThreshold(2);
•
String[] androidVersionNames = {"Aestro", "Blender",
"CupCake", "Donut", "Eclair", "Froyo", "Gingerbread",
"HoneyComb", "IceCream Sandwich", "Jellibean", "Kitkat",
"Lollipop", "MarshMallow"};
• @Override protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // initiate a
MultiAutoCompleteTextView MultiAutoCompleteTextView
simpleMultiAutoCompleteTextView =
(MultiAutoCompleteTextView)
findViewById(R.id.simpleMultiAutoCompleteTextView); //
set adapter to fill the data in suggestion list
• ArrayAdapter<String> versionNames = new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
androidVersionNames);
simpleMultiAutoCompleteTextView.setAdapter(versionName
s); // set threshold value 1 that help us to start the
searching from first character
simpleMultiAutoCompleteTextView.setThreshold(1); // set
tokenizer that distinguish the various substrings by comma
simpleMultiAutoCompleteTextView.setTokenizer(new
MultiAutoCompleteTextView.CommaTokenizer()); }
Thank You
10

AutocompleteTextView And MultiAutoCompleteTextView