Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SearchView to perform search inside same activity

I have a searchView in my SearchActivity and it creates an intent to launch a SearchActivityResults according to the documentation here: http://developer.android.com/training/search/setup.html

How do I need to go if I want my SearchView to trigger a search from within my activity, when the soft keyboard lower right button is pressed to trigger the search?

like image 485
Stephane Maarek Avatar asked Mar 14 '15 12:03

Stephane Maarek


1 Answers

you just need to get your searchView menu , use override onCreateOptionsMenu

SearchView searchView = (SearchView) MenuItemCompat
            .getActionView(mSearchMenuItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {


        @Override
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            // do your search on change or save the last string in search
            return false;
        }
    });

    // you can get query  
    searchView.getQuery();
like image 85
Ramy Sabry Avatar answered Oct 15 '22 22:10

Ramy Sabry