Java Code Examples for android.support.v7.widget.SearchView#setSuggestionsAdapter()

The following examples show how to use android.support.v7.widget.SearchView#setSuggestionsAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
/** Create menu from XML
 */
@TargetApi(Build.VERSION_CODES.FROYO)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mMenu = menu;
    /* Note: on Android 3.0+ with an action bar this method
     * is called while the view is created. This can happen
     * any time after onCreate.
     */
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.media_library, menu);

    if (AndroidUtil.isFroyoOrLater()) {
        SearchManager searchManager =
                (SearchManager) VLCApplication.getAppContext().getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.ml_menu_search));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setQueryHint(getString(R.string.search_hint));
        SearchSuggestionsAdapter searchSuggestionsAdapter = new SearchSuggestionsAdapter(this, null);
        searchSuggestionsAdapter.setFilterQueryProvider(this);
        mSearchView.setSuggestionsAdapter(searchSuggestionsAdapter);
    } else
        menu.findItem(R.id.ml_menu_search).setVisible(false);
    return super.onCreateOptionsMenu(menu);
}
 
Example 2
Source File: MainActivity.java    From openshop.io-android with MIT License 5 votes vote down vote up
/**
 * Show user search whisperer with generated suggestions.
 *
 * @param query      actual search query
 * @param searchView corresponding search action view.
 */
private void showSearchSuggestions(String query, SearchView searchView) {
    if (searchSuggestionsAdapter != null && searchSuggestionsList != null) {
        Timber.d("Populate search adapter - mySuggestions.size(): %d", searchSuggestionsList.size());
        final MatrixCursor c = new MatrixCursor(new String[]{BaseColumns._ID, "categories"});
        for (int i = 0; i < searchSuggestionsList.size(); i++) {
            if (searchSuggestionsList.get(i) != null && searchSuggestionsList.get(i).toLowerCase().startsWith(query.toLowerCase()))
                c.addRow(new Object[]{i, searchSuggestionsList.get(i)});
        }
        searchView.setSuggestionsAdapter(searchSuggestionsAdapter);
        searchSuggestionsAdapter.changeCursor(c);
    } else {
        Timber.e("Search adapter is null or search data suggestions missing");
    }
}
 
Example 3
Source File: MainActivity.java    From moviedb-android with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the contents of the Activity's standard options menu.
 * This is only called once, the first time the options menu is displayed.
 *
 * @param menu the options menu in which we place our items.
 * @return You must return true for the menu to be displayed; if you return false it will not be shown.
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    searchViewItem = menu.findItem(R.id.search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);

    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    searchView.setOnQueryTextListener(searchViewOnQueryTextListener);
    searchView.setOnSuggestionListener(searchSuggestionListener);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchViewItemC =
            (SearchView) menu.findItem(R.id.search).getActionView();
    searchViewItemC.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));


    String[] from = {SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2};
    int[] to = {R.id.posterPath, R.id.title, R.id.info};
    searchAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.suggestionrow, null, from, to, 0) {
        @Override
        public void changeCursor(Cursor cursor) {
            super.swapCursor(cursor);
        }
    };
    searchViewItemC.setSuggestionsAdapter(searchAdapter);

    MenuItemCompat.setOnActionExpandListener(searchViewItem, onSearchViewItemExpand);


    return true;
}
 
Example 4
Source File: BaseActivity.java    From open with GNU General Public License v3.0 5 votes vote down vote up
public boolean executeSearchOnMap(String query) {
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setSuggestionsAdapter(null);

    PagerResultsFragment pagerResultsFragment = PagerResultsFragment.newInstance(this);
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.pager_results_container, pagerResultsFragment,
                    PagerResultsFragment.TAG)
            .commit();
    return pagerResultsFragment.executeSearchOnMap(getSearchView(), query);
}