Skip to content

Instantly share code, notes, and snippets.

@kirikintha
Created December 30, 2013 18:19
Show Gist options
  • Save kirikintha/8185693 to your computer and use it in GitHub Desktop.
Save kirikintha/8185693 to your computer and use it in GitHub Desktop.
Suggestions Adapter - not generic, just for reference sake
//Create a cursor for suggestions.
@Deprecated
private void createSuggestions (String characters) {
suggestionsCursor = new MatrixCursor(columnNames);
int suggestionId = 0;
for (Manifests country : countries) {
String name = country.getName();
String check = name.toLowerCase();
if (check.startsWith(characters.toLowerCase())) {
//Create suggestions.
suggestion[0] = Integer.toString(suggestionId);
suggestion[1] = name;
suggestionsCursor.addRow(suggestion);
}
suggestionId++;
}
//Suggestions.
suggestionsAdapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_1,
suggestionsCursor, from, to, 0);
searchView.setSuggestionsAdapter(suggestionsAdapter);
searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
@Override
public boolean onSuggestionClick(int arg0) {
suggestionsCursor.moveToPosition(arg0);
String name = suggestionsCursor.getString(1);
searchView.setQuery(name, true);
return true;
}
@Override
public boolean onSuggestionSelect(int arg0) {
return false;
}
});
}
@kirikintha
Copy link
Author

private static final String[] columnNames = {"_id", "name"};
private static final String[] from = {"name"};
private static final int[] to = {android.R.id.text1};
private static String[] suggestion = new String[2];
private static MatrixCursor suggestionsCursor;
private static SimpleCursorAdapter suggestionsAdapter;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment