0

好球員的結果(「文本」),我有一個dinamycally查詢通過SimpleCursorAdapter我的數據庫來獲得我想要的結果,並將其設置爲我自動完成的AutoCompleteTextView,AutoCompleteTextView未顯示從我SimpleCursorAdapter

好吧,我知道這裏有很多帖子和互聯網上的教程,我跟着他們,嘗試了很多次完成這個事情,但我找不到解決方案,所以下面是我的代碼和實際發生的照片。 ..

這裏是調用方法我在我的表格挑值AutoCompleteTextView ...

AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.clienteACTV); 
    actv.setTextColor(getResources().getColor(android.R.color.black)); 

    final int[] to = new int[] { R.id.clienteACTV }; 
    // String substring = nota_helper.getCliente(); 
    // Cursor managedCursor = dao.searchClientes(substring, substring); 

    final String[] from = new String[] { "KUNNR" }; 
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.select_dialog_item, null, from, to, SimpleCursorAdapter.NO_SELECTION); 

    actv.setAdapter(adapter); 

    adapter.setCursorToStringConverter(new CursorToStringConverter() { 

     @Override 
     public CharSequence convertToString(Cursor cursor) { 
      int index = cursor.getColumnIndex("KUNNR"); 
      return cursor.getString(index); 
     } 
    }); 

    adapter.setFilterQueryProvider(new FilterQueryProvider() { 
     public Cursor runQuery(CharSequence str) { 
      String substring = null; 

      if (str != null) { 
       substring = str.toString(); 
      } 

      //Cursor managedCursor = dao.searchClientes(substring, substring); 
      Cursor managedCursor = dao.getCursor(substring); 
      Log.d("0", "Query has " + managedCursor.getCount() + " rows of description for " + substring); 
      return managedCursor; 
     } 
    }); 

這裏是我的分貝我的查詢方法:如果你們需要再代碼只是讓我知道,我在這裏更新...

public Cursor searchClientes(String substring, String index) { 
    System.out.println("searchClientesssssssssssssssssssssssssssssssssssssss"); 
    //return DBHelper.getReadableDatabase().rawQuery("Select *, rowid AS _id from " + TB_CLIENTE + " where KUNNR like '" + substring + "%';", null); 

    return DBHelper.getReadableDatabase().rawQuery("Select KUNNR from " + TB_CLIENTE + " where KUNNR like '" + substring + "%';", null); 

} 

enter image description here

+0

我的文字顯示但不可見,請嘗試更改文字顏色代碼。 – Ravi 2014-12-13 03:35:52

+0

logcat顯示什麼:Log.d(「0」,「Query has」+ managedCursor.getCount()+「」substring的描述行); ?也嘗試使用DatabaseUtils.dumpCursor()來顯示您的光標 – pskink 2014-12-13 03:44:04

+0

的內容,請參閱此鏈接(https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html) – krishnan 2014-12-13 04:11:31

回答

0

Here is your answer

變化

final int[] to = new int[] { R.id.clienteACTV }; 

final static int[] to = new int[] { android.R.id.text1 }; 
相關問題