Setting custom values to Searchview Adapter
like we do in autocomplete and passing array string
I tried this code:
private void setupSearchView(MenuItem searchItem) {
if (isAlwaysExpanded()) {
mSearchView.setIconifiedByDefault(false);
} else {
searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
}
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
for (SearchableInfo inf : searchables) {
if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
info = inf;
}
}
mSearchView.setSearchableInfo(info);
}
mSearchView.setOnQueryTextListener(this);
}
SearchView
takes a CursorAdapter
only:
setSuggestionsAdapter(CursorAdapter adapter)
Unfortunately that means you can't just supply an ArrayAdapter
with an array of items. If you really wanted to use a String[]
as searchable data source, I suppose you could wrap it into a MatrixCursor
.
An example is can be found here:
Please go through these links. You will get it what you want.
http://looksok.wordpress.com/2013/06/15/android-searchview-tutorial-edittext-with-phone-contacts-search-and-autosuggestion/
http://innovativenetsolutions.com/2013/07/android-tutorial-search-interface-search-dialog/
http://www.thaicreate.com/mobile/android-searchview.html
https://www.grokkingandroid.com/android-tutorial-adding-search-to-your-apps/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With