【问题标题】:MultiAutoCompleteTextView adds ", "MultiAutoCompleteTextView 添加“,”
【发布时间】:2011-10-03 10:34:39
【问题描述】:

我有一个 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());
          }
      }

【问题讨论】:

    标签: android


    【解决方案1】:

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

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

    或者,如果您想继续使用 ',' 作为分隔符,则必须手动从 MultiAutoCompleteTextView 中获得的最终字符串中删除最后一个逗号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-18
      相关资源
      最近更新 更多