AutoCompleteTextView displays 'android.database.sqlite.SQLiteCursor@'… after making selection

前端 未结 4 1744
春和景丽
春和景丽 2021-02-08 10:25

I am using the following code to set the adapter (SimpleCursorAdapter) for an AutoCompleteTextView

mComment = (AutoCompleteTextView) findViewById(R.id.comment);
         


        
4条回答
  •  日久生厌
    2021-02-08 11:00

    [Late answer, just for the record. EDITed to remove my suggestion that subclassing is necessary.]

    To use SimpleCursorAdapter with an AutoCompleteTextView, you need to set two handlers on the adapter: The CursorToStringConverter, and the FilterQueryProvider. Pseudocode follows:

        adapter.setCursorToStringConverter(new CursorToStringConverter() {
            public String convertToString(android.database.Cursor cursor) {
                // Assume that "someColumn" contains the strings that we want to
                // use to identify rows in the result set.
                final int columnIndex = cursor.getColumnIndexOrThrow("someColumn");
                final String str = cursor.getString(columnIndex);
                return str;
            }
        });
    
        adapter.setFilterQueryProvider(new FilterQueryProvider() {
            public Cursor runQuery(CharSequence constraint) {
                // runSomeQuery will look for all rows in the database
                // that match the given constraint.
                Cursor cursor = runSomeQuery(constraint);
                return cursor;
            }
        });
    

提交回复
热议问题