Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between MultiAutoCompleteTextView and AutoCompleteTextView

Can someone explain the difference between MultiAutoCompleteTextView and AutoCompleteTextView?

like image 644
Pankaj Kumar Avatar asked Feb 03 '11 09:02

Pankaj Kumar


People also ask

What is the difference between AutoCompleteTextView and MultiAutoCompleteTextView?

Difference Between AutoCompleteTextView and MultiAutoCompleteTextView. An AutoCompleteTextView only offers suggestion about the whole text. But MultiAutoCompleteTextView offers multiple suggestions for the substring of the text.

What is MultiAutoCompleteTextView?

android.widget.MultiAutoCompleteTextView. An editable text view, extending AutoCompleteTextView , that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing. You must provide a Tokenizer to distinguish the various substrings.

What does Android completion hint attribute in autocomplete text view does?

This defines the hint view displayed in the drop down menu. This defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu. This is the View to anchor the auto-complete dropdown to.


2 Answers

AutocompleteTextView only offers suggestions about the whole sentence and MultiAutoCompleteTextView offers suggestions for every token in the sentence. You can specify what is the delimiter between tokens.

String[] words=new String[] {      "word1", "word2", "word3", "word4", "word5"  };  MultiAutoCompleteTextView macTv = (MultiAutoCompleteTextView) this.findViewById(R.id.mac_tv); ArrayAdapter<String> aaStr = new ArrayAdapter<String>(this,android.R.layout.dropdown_item,words); macTv.setAdapter(aaStr); macTv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer() ); 

and:

<MultiAutoCompleteTextView  android:id="@+id/mac_tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:completionThreshold="1" /> 

with this example the suggestion comes after every comma.

like image 77
Eric Avatar answered Sep 23 '22 11:09

Eric


The choice between using the AutoCompleteTextView or the MultiAutoCompleteTextView comes down to whether or not the user should be allowed to input only "one item" as provided by the adapter, or "multiple items."

So for example, if you were writing an email app, and you wanted the "To:" field to be an autocomplete field, pulling matches from an address book, chances are you want to allow the user to pick multiple recipients for a message, and would make this field a MultiAutoCompleteTextView.

On the other hand, the "From:" field in the same example email app, you would need to enforce only a single selection by the user from their configured email accounts. And so an AutoCompleteTextView would be appropriate here.

like image 45
d60402 Avatar answered Sep 22 '22 11:09

d60402