title: Search button in toolbar for fragment is not displaying keyboard
body: <p>I have multiple fragments in an activity where I want a search button in the toolbar. In one of my fragments this all successfully works but when I copied the exact same code into my other two fragments they aren't functioning properly.</p>
  
  <p>When I click the search button on the working fragment, the keyboard pops up and I can start entering text. But on the other two fragments when I press on the search button icon, it slides to the left and then I need to press it again for it to work. Anyone know how I can fix this?</p>
  
  <p><img src="https://i.stack.imgur.com/4GWs7.jpg" width="300">
  <img src="https://i.stack.imgur.com/64IeJ.jpg" width="300"></p>
  
  <pre><code>    @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      inflater.inflate(R.menu.search, menu);
      MenuItem item = menu.findItem(R.id.action_search);
      SearchView sv = new SearchView(((Home) getActivity()).getSupportActionBar().getThemedContext());
      MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
      MenuItemCompat.setActionView(item, sv);
      sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
              return false;
          }
  
          @Override
          public boolean onQueryTextChange(String newText) {
              list.clear();
              for (int i = 0; i &lt; mainList.size(); i++) {
                  if (mainList.get(i).getName().toLowerCase().startsWith(newText.toLowerCase(), 0) || mainList.get(i).getAddress().toLowerCase().startsWith(newText.toLowerCase())) {
                      list.add(mainList.get(i));
                  }
              }
              adapter.notifyDataSetChanged();
              return false;
          }
      });
  
      super.onCreateOptionsMenu(menu, inflater);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch(item.getItemId())
      {
      case R.id.action_search:
          getActivity().onSearchRequested();
          return true;
  
      default:
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>