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

前端 未结 4 1741
春和景丽
春和景丽 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:13

    To solve the problem I just extended SimpleCursorAdapter and implemented the method convertToString(). Then I created an instance and set it as the adapter.

    In order to allow filtering in AutoCompleteTextView when using CursorAdapters I also used setFilterQueryProvider(). See this question.

    My extended class inside the Activity looks as:

    private static class AutoCompleteCursorAdapter extends SimpleCursorAdapter {
    
        public AutoCompleteCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);
        }
    
        @Override
        public CharSequence convertToString(Cursor cursor) {
            // This is the method that does the trick (return the String you need)
            return cursor.getString(cursor.getColumnIndex("name"));
        }
    }
    

提交回复
热议问题