title: How to dismiss/close/collapse SearchView in ActionBar in MainActivity?
body: <p>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.</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main_actions, menu);
  
      searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
      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 + "&amp;lang=pl").execute();
          try {
              searchView.onActionViewCollapsed();
          }
          catch(Exception ex){
              ex.printStackTrace();
              System.out.println(ex);
          }
          return true;
      }
  };
  </code></pre>
  
  <p>I can search only for the first time. Every next time it only closes my input keyboard and does nothing. How can it be performed in a right way?    </p>
  
  <p>Edit.
  Suggested change looks like this:</p>
  
  <pre><code>        try {
              searchView.setIconified(true);
          }
  </code></pre>
  
  <p>activity_main_actions.xml:</p>
  
  <pre><code>   &lt;!-- Search Widget --&gt;
     &lt;item android:id="@+id/action_search"
         android:icon="@drawable/ic_action_search"
         android:title="@string/action_search"
         android:showAsAction="always"
         android:actionViewClass="android.widget.SearchView"/&gt;
  </code></pre>
  
  <p>Edit2:</p>
  
  <p>I changed <code>showAsAction="always|collapseActionView"</code> but it closes my app when I click the search.</p>
  
  <p>I also put the listener inside OnCreateOptionsMenu to see if it changes anything:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main_actions, menu);
      searchMenuItem = menu.findItem(R.id.action_search); 
      searchView = (SearchView) searchMenuItem.getActionView();
      searchView.setOnQueryTextListener(new OnQueryTextListener(){
  
              @Override
              public boolean onQueryTextChange(String arg0) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextSubmit(String query) {
                  if (searchMenuItem != null) {
                      boolean closed = searchMenuItem.collapseActionView();
                      Toast.makeText(getApplicationContext(), "closing: " + closed, Toast.LENGTH_SHORT).show();
                  }
                  new JsoupGetData("http://api.openweathermap.org/data/2.5/find?q="+ query + "&amp;lang=pl").execute();
                  return false;
              }
      });    
      return super.onCreateOptionsMenu(menu);
  }
  </code></pre>
  
  <p>And the <code>closed</code> boolean is <code>false</code> - I don't know why. I read <a href="http://developer.android.com/reference/android/view/MenuItem.html#collapseActionView()" rel="noreferrer">the doc</a> but it tells me nothing.</p>
  
  <p>Edit3:</p>
  
  <p>I've read too much Internet on this subject and it is not clear for me yet. Search widget is cleared, keyboard is hidden and action is performed. The only issue is the search isn't collapsed so it covers the rest of action buttons on the ActionBar.</p>
  
  <pre><code>            @Override
              public boolean onQueryTextSubmit(String query) {
                  searchView.setIconified(true);
                  searchView.clearFocus();
                  new JsoupGetData("http://api.openweathermap.org/data/2.5/find?q="+ query + "&amp;lang=pl").execute();
                  return false;
              }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/a/23123777/2194222">Here</a> I read that collapseActionView() will not work, because my Search is not a view but a widget.</p>