Search code examples
androidsearchview

Android SearchView: Modify search query on submit


I want to prepend a tag to the query for further use, without it appearing in the SearchView.

I tried to use setQuery() in the OnQueryTextListener but it doesn't put the tag in the query passed to the results activity. Also, when the user presses the "back" button from the results activity the tag is showing the SearchView field.

private OnQueryTextListener searchQueryListener = new OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {

       searchView.setQuery(myTag + query,false);
        return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        return true;
    }

};

Solution

  • If you return true in onQueryTextSubmit you can handle the query yourself.