I have a search view that has the suggestions populated by a MatrixCursor (because I already have an array of Strings). However I would like to get which item is being selected by the user. So far I am only able to get the position where the user has clicked on the suggestion list:
searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
@Override
public boolean onSuggestionClick(int position) {
String selectedItem = (String)mAdapter.getItem(position);
Log.e("search view", selectedItem);
return true;
}
However I have got an error: android.database.MatrixCursor cannot be cast to java.lang.String and I am not sure how to go around with it. Really appreciate for any kind of help.
The position brings the suggested list selected item position. If your suggested list is a
Cursor(from theExceptionI may think is aMatrixCursor), you have to get the item that is in the position of the Cursor.columnOfTheItemStringInTheMatrixis the column number that you assigned when you created the Matrix and added the row. For example:and when you added a row (a new item to the MatrixCursor):
Then the
columnOfTheItemStringInTheMatrix = 0;