I\'m trying to clear and close SearchView after entering a value. I found a solution but it closes the search and won\'t perform any action if I try to search again.
Hi i faced a similar scenario and so i think this changed to code should do the trick.
Hope this helps...:)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main_actions, menu);
Menu mMenuItem = menu.findItem(R.id.action_search_loc); // take a reference with menue item
searchView = (SearchView) mMenuItem.getActionView(); //use that to find searchview
searchView.setOnQueryTextListener(searchListener);
return super.onCreateOptionsMenu(menu);
}
SearchView.OnQueryTextListener searchListener = new SearchView.OnQueryTextListener(){
@Override
public boolean onQueryTextChange(String arg0) {
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
new JsoupGetData("http://api.openweathermap.org/data/2.5/find?q="+ query + "&lang=pl").execute();
try {
mMenuItem.collapseActionView(); //this will collapse your search view
}
catch(Exception ex){
ex.printStackTrace();
System.out.println(ex);
}
return true;
}
};