androiduser-interfaceautocompletetextviewmultiautocompletetextview

Difference between MultiAutoCompleteTextView and AutoCompleteTextView


Can someone explain the difference between MultiAutoCompleteTextView and AutoCompleteTextView?


Solution

  • 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.