gpt4 book ai didi

android - 从下拉列表中选择字符串后,MultiAutoCompleteTextView 字符串得到 ","?

转载 作者:行者123 更新时间:2023-11-30 02:25:54 26 4
gpt4 key购买 nike

我将 MultiAutoCompleteTextView 集成到我的字典应用程序中,所以现在集成它之后。

我在第二个屏幕截图中遇到了这样的问题...

所以现在我不想要那个 ","

如 ! 之后的第二个屏幕截图所示

我得到这样的“,”

!,

请帮帮我谢谢Q

enter image description here

enter image description here

String[] str={"!","\"","#","$","$1","%","'","+",",","/"};

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复制了代码

关于android - 从下拉列表中选择字符串后,MultiAutoCompleteTextView 字符串得到 ","?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27919643/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com