In order to be able to enter several words through the separator with autocompletion of each, you need to use the MultiAutoCompleteTextView widget.
Example:
private static final String[] COUNTRIES = new String[] {"Belgium", "France", "Italy", "Germany", "Spain"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES); MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.edit); textView.setAdapter(adapter); textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
The widget needs to set the delimiter with the setTokenizer() method, which will separate the words entered with autocompletion. In the example, the separator is a ready-made comma-separated class - CommaTokenizer()
If the comma does not suit you as a separator, you can write your own class with the necessary separator (for example, ";"):
public static class SemicolonTokenizer implements Tokenizer { public int findTokenStart(CharSequence text, int cursor) { int i = cursor; while (i > 0 && text.charAt(i - 1) != ';') { i--; } while (i < cursor && text.charAt(i) == ' ') { i++; } return i; } public int findTokenEnd(CharSequence text, int cursor) { int i = cursor; int len = text.length(); while (i < len) { if (text.charAt(i) == ';') { return i; } else { i++; } } return len; } public CharSequence terminateToken(CharSequence text) { int i = text.length(); while (i > 0 && text.charAt(i - 1) == ' ') { i--; } if (i > 0 && text.charAt(i - 1) == ';') { return text; } else { if (text instanceof Spanned) { SpannableString sp = new SpannableString(text + "; "); TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0); return sp; } else { return text + "; "; } }
and then specify as separator:
textView.setTokenizer(new SemicolonTokenizer());