2010-11-16 92 views
0

我通過擴展AutoCompleteTextView(使用名爲setCursorAdapter的專用函數)來創建自定義視圖。我提供了一個SimpleCursorAdapter並添加了一個FilterQueryProvider。我使用這個數字列表,我需要能夠搜索匹配數字中的任何地方。使用AutoCompleteTextView將文本自定義光標

public void setCursorAdapter(final Uri uri, final String key) { 

     Cursor c = getContext().getContentResolver().query(uri, 
       new String[] { "_id", key }, null, null, key); 
     SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(), 
       android.R.layout.simple_dropdown_item_1line, c, 
       new String[] { key }, new int[] { android.R.id.text1 }); 

     this.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, 
        int count) { 
       ((SimpleCursorAdapter) getAdapter()).getFilterQueryProvider() 
         .runQuery(s); 

      } 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, 
        int after) { 
       // TODO Auto-generated method stub 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       // TODO Auto-generated method stub 

      } 
     }); 

     adapter.setFilterQueryProvider(new FilterQueryProvider() { 

      @Override 
      public Cursor runQuery(CharSequence constraint) { 
       Cursor c = getContext().getContentResolver().query(uri, 
         new String[] { "_id", key }, 
         key + " LIKE '%" + constraint + "%'", null, key); 
       return c; 
      } 
     }); 
     setAdapter(adapter); 
    } 

一切都很完美,直到我從下拉列表中選擇數值。我在EditText窗口中收到的值:android.content.ContentResolver $ CursorWrapperInner @ ...

如何避免這種情況並使我的(數字)文本正確顯示。

由於

回答

1

解決:SimpleCursorAdapter.converToString(光標) - 我推翻這個函數提取的值。

感謝