I have a MultiAutoCompleteTextView. When i enter "Sal" it suggest "Salami" , but when i press it in the box stands "Salami, ".
How could i prefent that?
My Code:
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());
}
}
In MultiAutoCompleteTextView,it would always need separator so i think,you can't get rid of it. But you can use space as seperator instead of comma and then you can trim your final string for further use. You can find solution here -
How to replace the comma with a space when I use the "MultiAutoCompleteTextView"
Or if you want to continue using ',' as separator,then you would have to manually remove last comma from a final string you get in MultiAutoCompleteTextView.
精彩评论