Multi AutoComplete TextView

If you have played with the AutoCompleteTextView control, then you know that the control offers suggestions only for the entire text in the text view. In other words, if you type a sentence, you don't get suggestions for each word. That's where MultiAutoCompleteTextView comes in. You can use the MultiAutoCompleteTextView to provide suggestions as the user types. For example, Figure 4-2 shows that the user typed the word English followed by a comma, and then Hi, at which point the control suggested Hindi. If the user were to continue, the control would offer additional suggestions.

Using the MultiAutoCompleteTextView is like using the AutoCompleteTextView. The difference is that you have to tell the control where to start suggesting again. For example, in Figure 4-2, you can see that the control can offer suggestions at the beginning of the sentence and after it sees a comma. The MultiAutoCompleteTextView control requires that you give it a tokenizer that can parse the sentence and tell it whether to start suggesting again. Listing 4-8 demonstrates using the MultiAutoCompleteTextView control.

Listing 4-8. Using the MultiAutoCompleteTextView Control

MultiAutoCompleteTextView mactv = (MultiAutoCompleteTextView) this

.findViewById(R.id.ccmactv); ArrayAdapter<String> aa2 = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, new String[] {"English", "Hebrew", "Hindi", "Spanish", "German","Greek" });

mactv.setAdapter(aa2);

mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

The only significant difference between Listing 4-7 and Listing 4-8 is the use of MultiAutoCompleteTextView and the call to the setTokenizer() method.

0 0

Post a comment