我有一个 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/