Difference between MultiAutoCompleteTextView and AutoCompleteTextView

AndroidUser InterfaceAutocompletetextviewMultiautocompletetextview

Android Problem Overview


Can someone explain the difference between MultiAutoCompleteTextView and AutoCompleteTextView?

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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.

Solution 3 - Android

Difference between AutoCompleteTextView and MultiAutoCompleteTextView

AutoCompleteTextView Vs MultiAutoCompleteTextView

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

AutoCompleteTextView is used for selecting single Item MultiAutoCompleteTextView is used for for selecting multiple Items by using a delimiter(such as comma) in betwwen them.

the “From:” field in example of email app, you would need to enforce only a single selection by the user from their configured email accounts. If you were writing an email app, and you wanted the “To:” field to be an autocomplete field, getting matches from an address book, chances you want to allow the user to pick multiple recipients for a message, and would make this field a MultiAutoCompleteTextView

Solution 4 - Android

  • AutocompleteTextView only offers suggestions about the whole sentence
  • MultiAutoCompleteTextView offers suggestions for every token in the sentence.

You can specify what is the delimiter between tokens also set the first or any no. of characters using setThreshold() with MultiAutoCompeleteTextView control in Android.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPankaj KumarView Question on Stackoverflow
Solution 1 - AndroidEricView Answer on Stackoverflow
Solution 2 - Androidd60402View Answer on Stackoverflow
Solution 3 - AndroidDr. Parag C ShuklaView Answer on Stackoverflow
Solution 4 - AndroidAshoksinh Zala AcademyView Answer on Stackoverflow