how to change android SearchView text how to change android SearchView text android android

how to change android SearchView text


After wondering and trying I found out that there is a method in the API named setQuery() which you set the searchView text and you may choose to submit the search or not using the boolean parameter.

searchView.setQuery(searchToken, false);


You can use setQuery() to change the text in the textbox.

However, setQuery() method triggers the focus state of a search view, so a keyboard will show on the screen after this method has been invoked.

To fix this problem, just call searchView.clearFocus() after setQuery() method to unfocus it and the keyboard will not show on the screen.

Example:

String suggestWord = intent.getDataString();searchView.setQuery(suggestWord, false);searchView.clearFocus();


this is what worked for me

    MenuItem sItem = menu.findItem(R.id.search);    SearchView searchView = (SearchView) sItem.getActionView();    sItem.expandActionView();    searchView.setQuery("your text", false);