Created
December 30, 2013 18:19
-
-
Save kirikintha/8185693 to your computer and use it in GitHub Desktop.
Suggestions Adapter - not generic, just for reference sake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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;