What you're looking for is a MultiAutocompleteTextView: http://developer.android.com/reference/android/widget/MultiAutoCompleteTextView.html
Here's a Tokenizer I used for the same purpose. I use a custom Span to denote a profile tag called ProfileTagSpan, which is necessary because I need to display the profile name to the user but save the profile ID in the string. Yours could be simpler if this is not necessary.
public class ProfileTagTokenizer implements MultiAutoCompleteTextView.Tokenizer {
/*
* Search back from cursor position looking for @ symbol
* If none found then cancel filtering by making the constraint length 0
* Also cancel if another tag found as tags can't overlap
*/
public int findTokenStart(CharSequence text, int cursor) {
for (int i = cursor; i > 0; i--) {
if (text.charAt(i - 1) == '@') return i;
else if (text instanceof Spanned &&
((Spanned) text).getSpans(i, i, ProfileTagSpan.class).length > 0) break;
}
return cursor;
}
/*
* Use the cursor position for token end as we have no delimiter on the tag
*/
public int findTokenEnd(CharSequence text, int cursor) {
return cursor;
}
/*
* Add a space after the tag
*/
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 + " ";
}
}
}
}