I have done like this
the onQueryTextSubmit
is the method you are looking for.
set setOnQueryTextListener
on your search view.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
MenuItem searchItem = menu.findItem(R.id.search_city);
searchView = (SearchView) searchItem.getActionView();
searchView.setQueryHint("Search View Hint");
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
//Log.e("onQueryTextChange", "called");
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
// Do your task here
return false;
}
});
return true;
}
hope this help
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…