我需要为不同的令牌设置不同的适配器(例如,当我键入'@'时,它应该调用AttionedAdapter,当我键入'#'时,它应该调用hashAdapter,两者必须在同一个MultiAutoCompleteTextView中
请找到我目前使用的代码示例,它适用于@但不适用于散列
multiTextview.setTokenizer(new MultiAutoCompleteTextView.Tokenizer() {
@Override
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 + " ";
}
}
}
@Override
public int findTokenStart(CharSequence text, int cursor) {
int i = cursor;
while ((i > 0 && text.charAt(i - 1) != '@') || (i > 0 && text.charAt(i - 1) != '#')) {
i--;
}
//Check if token really started with @, else we don't have a valid token
if (i < 1 || text.charAt(i - 1) != '@') {
return cursor;
}
if (i < 1 || text.charAt(i - 1) != '#') {
return cursor;
}
return i;
}
@Override
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;
}
});
任何人都可以帮助我,请我坚持下去