Igor Lobanov Igor Lobanov - 1 year ago 364
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:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download