Reputation: 95
I'm trying to use a custom CursorAdapter
(by inheriting from CursorAdapter
) overriding bindView(...)
and newView(...)
as suggested here (examplecursoradapter).
However, when using it with an AutoCompleteTextView
, the auto-completed value (i.e. the value entered when the user selects a value from the drop down list) inserted is the toString()
value of the SqliteCursor
. How can I obtain the value in the drop-down list, using this method?
Upvotes: 4
Views: 1616
Reputation: 6598
You also need to define convertToString(Cursor)
method for your custom CursorAdapter.
For example:
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 examples from ApiDemos(files AutoComplete4.java and AutoComplete5.java from <android-sdk-dir>\samples\android-15\ApiDemos\src\com\example\android\apis\view
Upvotes: 7