2011-10-03 38 views
1

我有一個MultiAutoCompleteTextView。當我輸入「薩爾」時,它提示「薩拉米」,但是當我按下框中的立場「薩拉米」時。MultiAutoCompleteTextView增加「,」

我怎麼能指望?

我的代碼:

無效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()); 
      } 
     } 

回答

3

在MultiAutoCompleteTextView,它總是需要分離,所以我認爲,你無法擺脫它。但你可以使用空格作爲分隔符而不是逗號,然後你可以修剪你的最終字符串以備後用。你可以在這裏找到解決方案 -

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

或者,如果你想繼續使用「」作爲分隔符,那麼你就必須手動從您在MultiAutoCompleteTextView得到一個最終的字符串中刪除最後一個逗號。

+2

你能分享識別','的代碼並手動刪除它.... ?? – VijayRaj