How to install the adapter for search in the action bar

Setting custom values Searchview Adapter

as in autocomplete and transferring an 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);
}
+4
source share
2 answers

SearchViewaccepts only CursorAdapter:

Unfortunately, this means that you cannot just provide an ArrayAdapterarray of elements. If you really wanted to use String[]as a data source for the search, I suppose you can translate it into MatrixCursor.

An example can be found here:

+8
source

All Articles