Situation
I have a searchview where the user can search for an item located in a local sqlitedatabase and a list of suggestions will pop up while the user is typing. I do this using a MatrixCursor, the support library's SimpleCursorAdapter, and searchview.setSuggestionAdapter(). This works fine in portrait mode, but has a problem in landscape.
The problem is that instead of the desired custom suggestion appearing, android.database.Matrix... appears.
Problem
How do I get my custom suggestions to show up in landscape mode (either in the softkeyboard or anywhere)? I don't have the option of disabling the hints altogether because the user will be confused if they misspell the item and then expect the result to appear when it doesn't.
Code
Fragment.java
private void setUpSingleSearch(final Menu menu, final MenuItem singleSearchItem) {
searchView = (SearchView) MenuItemCompat.getActionView(singleSearchItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
displaySuggestions(newText);
return false;
}
});
}
private void displaySuggestions(String query) {
MatrixCursor matrixCursor = new MatrixCursor(new String[]{BaseColumns._ID,
RestaurantTable.Cols.NAME, RestaurantTable.Cols.ID});
RestaurantListing restaurantListing = new RestaurantListing(getContext());
restaurantListing.getRestaurantSuggestions(currListName, "Name", matrixCursor, query);
setUpSearchViewSuggestions(matrixCursor);
}
private void setUpSearchViewSuggestions(MatrixCursor cursor) {
String[] from = new String[]{RestaurantTable.Cols.NAME};
int[] to = new int[]{android.R.id.text1};
android.support.v4.widget.SimpleCursorAdapter adapter = new android.support.v4.widget.SimpleCursorAdapter(
getActivity().getBaseContext(),
R.layout.search_view_suggestions_list_item,
cursor,
from,
to,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
searchView.setSuggestionsAdapter(adapter);
}