gpt4 book ai didi

android - MultiAutoCompleteTextView 添加 ", "

转载 作者:行者123 更新时间:2023-11-29 18:16:53 25 4
gpt4 key购买 nike

我有一个 MultiAutoCompleteTextView。当我输入“Sal”时,它会提示“Salami”,但当我在框中按下它时,它会显示“Salami,”。

我怎么能阻止呢?

我的代码:

void addAutoSuggest ()

{
myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
ArrayList<String> list = new ArrayList<String>();
Cursor cursor = this.myDB.query(MY_DB_TABLE, new String[] {"name"},null,null,null,null,null,null);
if (cursor.moveToFirst()) {
do {
String str= cursor.getString(0);
list.add(str);
}
while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
if (list!=null)
{
name.setAdapter( new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, list));
name.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}

最佳答案

在 MultiAutoCompleteTextView 中,它总是需要分隔符,所以我认为,你无法摆脱它。但是您可以使用空格代替逗号作为分隔符,然后您可以修剪最终字符串以供进一步使用。您可以在这里找到解决方案 -

How to replace the comma with a space when I use the "MultiAutoCompleteTextView"

或者,如果您想继续使用“,”作为分隔符,那么您将不得不从您在 MultiAutoCompleteTextView 中获得的最终字符串中手动删除最后一个逗号。

关于android - MultiAutoCompleteTextView 添加 ", ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7633846/

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