How can I use a custom CursorAdapter with an AutoCompleteTextView?

I am trying to use a custom CursorAdapter (by inheriting from a CursorAdapter ), overriding bindView(...) and newView(...) as suggested here ( examplecursoradapter ).

However, when used with an AutoCompleteTextView , the autocomplete value (i.e. the value entered when the user selects a value from the drop-down list) is the toString() value for SqliteCursor . How can I get the value from the dropdown using this method?

+4
source share
1 answer

You also need to define a convertToString(Cursor) method for your custom CursorAdapter.

For instance:

 public static class YourAdapter extends CursorAdapter implements Filterable{ //bindView(), newView() etc... @Override public String convertToString(Cursor cursor) { //returns string inserted into textview after item from drop-down list is selected. return cursor.getString(cursor.getColumnIndexOrThrow(NAME_OF_COLUMN_DISPLAYED_IN_DROP_DOWN)); } } 

You can also check the examples from ApiDemos (AutoComplete4.java and AutoComplete5.java files from <android-sdk-dir>\samples\android-15\ApiDemos\src\com\example\android\apis\view

+7
source

All Articles