Igor Lobanov Igor Lobanov - 9 months ago 209
Java Question

The onQueryTextSubmit in SearchView is processed twice in Android Java

Why the

method in
is processed twice?
I need one result, how can I do it?

This is my code:

public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
public boolean onQueryTextSubmit(String query) {
if (query != null)
return false;

public boolean onQueryTextChange(String newText) {
return false;
return true;

Answer Source

You can use the following code to prevent onQueryTextSubmit from getting executed twice: