从下拉列表中选择字符串后,MultiAutoCompleteTextView 字符串得到“,”?
MultiAutoCompleteTextView strings getting "," after selecting string from drop down?
我将 MultiAutoCompleteTextView
集成到我的字典应用程序中,所以在集成它之后。
我遇到了这样的问题,如第二个屏幕截图所示...
所以现在我不想要那个 ","
如 !
之后的第二个屏幕截图所示
我得到这样的“,”
!,
请帮助我
谢谢q
String[] str={"!","\"","#","$","","%","'","+",",","/"};
MultiAutoCompleteTextView mt=(MultiAutoCompleteTextView)findViewById(R.id.searchEditText);
mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
ArrayAdapter<String> adp=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,str);
mt.setThreshold(1);
mt.setAdapter(adp);
逗号来自 CommaTokenizer()
这一行 mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
要删除逗号,您需要实现自己的 Tokenizer。这是一个例子:
public class SpaceTokenizer 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 + " ";
}
}
}
}
PS:我从this answer
复制了代码
我将 MultiAutoCompleteTextView
集成到我的字典应用程序中,所以在集成它之后。
我遇到了这样的问题,如第二个屏幕截图所示...
所以现在我不想要那个 ","
如 !
之后的第二个屏幕截图所示我得到这样的“,”
!,
请帮助我 谢谢q
String[] str={"!","\"","#","$","","%","'","+",",","/"};
MultiAutoCompleteTextView mt=(MultiAutoCompleteTextView)findViewById(R.id.searchEditText);
mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
ArrayAdapter<String> adp=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,str);
mt.setThreshold(1);
mt.setAdapter(adp);
逗号来自 CommaTokenizer()
这一行 mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
要删除逗号,您需要实现自己的 Tokenizer。这是一个例子:
public class SpaceTokenizer 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 + " ";
}
}
}
}
PS:我从this answer
复制了代码