MultiAutoCompleteTextView不接受空格
我的问题是,当我在MultiAutoCompleteTextView
中建议句子时,当我按空格键时,建议消失。 例子:MultiAutoCompleteTextView不接受空格
建议的话:
THE ROCK
THE BALL
热
如果我写 “”,将显示所有的句子,但如果我写“ “(与空白)的建议被驳回。 我想要的是,如果你写了“THE”,那么在建议的单词中就会显示“THE ROCK”和“THE BALL”元素。
谢谢。
看一看这个帖子:
https://groups.google.com/forum/#!topic/android-developers/OrsN2xRpDmA 我只是碰到了类似的问题,并写了一个简单的多字推导。它默认为一个“,”分隔符,但您可以使用“setSeparator”方法将其设置为任何您喜欢的。 AutoCompleteTextView backed by CursorLoader
你应该实现MultiAutoCompleteTextView.Tokenizer
和下面创建一个spaceTokenizer: 或 因为它遇到了同样的问题,这个堆栈溢出的答案可能是有帮助的。然后设置multiAutoCompleteTextView.setTokenizer(new SpaceTokenizer());
public class SpaceTokenizer implements MultiAutoCompleteTextView.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 + " ";
}
}
}
}
工作,我已经有一个'CustomTokenizer',并不起作用。你的'Tokenizer'也不能工作 – cnbandicoot
我已经看到了帖子,它不适合我 – cnbandicoot