AutoCompleteTextView没有显示我的SimpleCursorAdapter的结果(" text")

时间:2014-12-13 03:22:42

标签: android sqlite cursor simplecursoradapter autocompletetextview

好的,我有一个AutoCompleteTextView,它通过SimpleCursorAdapter查询我的db dinamycally以获得我想要的结果并将它们设置为我的AutoComplete,

好吧我知道这里有很多帖子和互联网上的教程我跟着他们尝试这么多次完成但我找不到解决方案,所以下面是我的代码和实际的照片正在发生......

以下是我的表单中的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

1 个答案:

答案 0 :(得分:0)

Here is your answer

更改

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

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