1

I'm using a SearchView widget to perform a search which includes the query and some other information from CheckBoxes.

I followed the guide for using the SearchView widget and it works great - but because I have additional info to add to the search, I want to have a FloatingActionButton trigger the search.

My code so far for setting up the search

private void setUpSearchCard(View layout) {
    // Retrieve SearchManager and the SearchView
    final SearchManager searchManager = (SearchManager) getContext()
            .getSystemService((Context.SEARCH_SERVICE));
    mSearchView = (SearchView) layout.findViewById(R.id.search_view);

    // Direct the SearchView to the activity that will get the result
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(
            new ComponentName(getContext(), SwipeDeckActivity.class)
    ));

    // Expand the bar by default
    mSearchView.setIconifiedByDefault(false);
}

What I wish to add to this function is something like this

    // Set up the search fab
    mSearchFAB = (FloatingActionButton) layout.findViewById(R.id.fab_search_button);
    mSearchFAB.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSearchView.launchSearch();
        }
    });

How can I do that? (Obviously the query that was inserted should be sent)

P.S. I do not want to use the Android supplied button that pops on the SearchView

bluesummers
  • 11,365
  • 8
  • 72
  • 108

1 Answers1

0

I know this is old. But I just was looking for something similar.

Try the following code snippet,

mSearchView.setQuery()

Maybe this helps someone.

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
drewle
  • 26
  • 3