Example usage for android.widget SearchView setSearchableInfo

List of usage examples for android.widget SearchView setSearchableInfo

Introduction

In this page you can find the example usage for android.widget SearchView setSearchableInfo.

Prototype

public void setSearchableInfo(SearchableInfo searchable) 

Source Link

Document

Sets the SearchableInfo for this SearchView.

Usage

From source file:in.rab.ordboken.Ordboken.java

public SearchView initSearchView(Activity activity, Menu menu, String query, Boolean focus) {
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) activity.findViewById(R.id.mySearchView);

    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(new ComponentName(activity, MainActivity.class)));

    // Hack to get the magnifying glass icon inside the EditText
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);/*from   w w w .j ava2s .c  o m*/

    // Hack to get rid of the collapse button
    searchView.onActionViewExpanded();

    if (!focus) {
        searchView.clearFocus();
    }

    // searchView.setSubmitButtonEnabled(true);
    searchView.setQueryRefinementEnabled(true);

    if (query != null) {
        searchView.setQuery(query, false);
    }

    return searchView;
}

From source file:com.google.android.apps.mytracks.util.Api11Adapter.java

@Override
public void configureSearchWidget(Activity activity, final MenuItem menuItem) {
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
    searchView.setQueryRefinementEnabled(true);
}

From source file:no.group09.ucsoftwarestore.MainFragmentActivity.java

/**
 * Creates options menu/* w ww  . j a  va  2 s . c o  m*/
 */
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);

    //When the menu is created, check the preferences and set the correct text
    if (sharedPref.getBoolean("hide_incompatible", false)) {
        menu.getItem(1).setTitle("Hide incompatible");
        menu.getItem(1).setChecked(true);
    } else {
        menu.getItem(1).setTitle("Hide incompatible");
        menu.getItem(1).setChecked(false);
    }

    //Search bar for versions over API level 11
    int SDK_INT = android.os.Build.VERSION.SDK_INT;

    if (SDK_INT >= 11) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setSubmitButtonEnabled(true);
    }
    return true;
}

From source file:org.yuzhiqiang.itsmine.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()) {
        // Only show items in the action bar relevant to this screen
        // if the drawer is not showing. Otherwise, let the drawer
        // decide what to show in the action bar.
        getMenuInflater().inflate(R.menu.main, menu);
        restoreActionBar();/*from   w  w  w .ja  va2 s.  co  m*/

        // Get the SearchView and set the searchable configuration
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        // Assumes current activity is the searchable activity
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

        return true;
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:org.bwgz.quotation.activity.SearchResultsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.d(TAG, String.format("onCreateOptionsMenu - menu: %s", menu));
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    Intent intent = getIntent();/*from w  w w. j  a v  a 2 s .  co m*/
    if (intent != null) {
        int type = intent.getIntExtra(EXTRA_SEARCH_TYPE, FreebaseSearch.SEARCH_TYPE_KEYWORD);
        Log.d(TAG, String.format("onCreateOptionsMenu - type: %s", type));
        setSearchHint(menu, type);

        String query = intent.getStringExtra(SearchManager.QUERY);
        Log.d(TAG, String.format("onCreateOptionsMenu - query: %s", query));
        if (query != null) {
            searchView.setIconified(true);
            searchView.setQuery(query, false);
            searchView.clearFocus();
        }
    }

    return true;
}

From source file:com.deliciousdroid.activity.FragmentBaseActivity.java

@TargetApi(11)
public void setupSearch(Menu menu) {
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setSubmitButtonEnabled(false);
    }/* w w  w .  j  a  v  a  2s  .  co  m*/
}

From source file:com.tinbytes.simplesearchapp.SimpleListViewActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_simple_list_view, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search_animal));
    if (searchView != null) {
        searchView.setOnQueryTextListener(this);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(true);
    }/*  w ww .ja  va  2s .c  o m*/
    return true;
}

From source file:com.murati.oszk.audiobook.ui.BaseActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

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

    mMenu = menu;/*from   w  w w  . j  a va2  s. com*/
    return true;
}

From source file:net.seedboxer.seedroid.activities.fragments.DownloadsFragment.java

/**
 * Get the SearchView and set the searchable configuration
 * @param menu/*  w w  w.  j av  a2s . co m*/
 */
private void createFilteredMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setOnQueryTextListener(new OnQueryTextListener() {

        public boolean onQueryTextSubmit(String query) {
            adapter.getFilter().filter(query);
            return true;
        }

        public boolean onQueryTextChange(String newText) {
            adapter.getFilter().filter(newText);
            return true;
        }
    });
}

From source file:org.bwgz.quotation.activity.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    Log.d(TAG, String.format("onCreateOptionsMenu - menu: %s", menu));

    getMenuInflater().inflate(R.menu.options_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQueryHint(getString(R.string.search_keyword));

    final ListView drawerView = (ListView) findViewById(R.id.drawer);
    DrawerAdapter adapter = new DrawerAdapter(getResources().getStringArray(R.array.home_drawer), 0);
    drawerView.setAdapter(adapter);/* ww  w. j  av  a  2s .  co  m*/
    drawerView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, String.format("drawer - onItemClick - parent: %s  view: %s  position: %d  id: %d",
                    parent, view, position, id));

            drawerLayout.closeDrawer(drawerView);

            if (id == 1) {
                Intent intent = new Intent(parent.getContext(), QuotationsActivity.class);
                intent.putExtra(CategoryActivity.EXTRA_ITEM, QuotationsActivity.QUOTATIONS_ITEM_BOOKMARKS);
                startActivity(intent);
            }
        }
    });

    return true;
}