title: Is there a way to use SearchView in Fragment?
body: <p>First of all, thank you all for your (future) responses :)</p>
  
  <p>Below explanation of my problem:</p>
  
  <p>I have my main Activity named MainActivity and I use a Fragment inside it. So, my Fragment contains a SearchView and a ListView which will contains suggestions depending on user's input... Please notice that I don't use it in the ActionBar but in my layout file...</p>
  
  <p>Here is <strong>fragment_board_menu.xml</strong>, xml file lied to my Fragment <strong>BoardMenuFragment</strong> :</p>
  
  <pre><code>&lt;android.support.v7.widget.SearchView
          android:id="@+id/board_searchView"
          android:layout_marginLeft="3dp"
          android:layout_marginStart="3dp"
          android:background="@color/green"
          app:searchIcon="@drawable/ic_search"
          app:searchHintIcon="@drawable/ic_search"
          app:closeIcon="@drawable/ic_close"
          app:defaultQueryHint="@string/create_newboard_hint"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
      &lt;ListView
          android:layout_below="@+id/board_searchView"
          android:background="@drawable/listview_border"
          android:layout_marginBottom="@dimen/listview_border_marginBottom"
          android:layout_marginLeft="3dp"
          android:layout_marginStart="3dp"
          android:id="@+id/board_listView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;
  </code></pre>
  
  <p>He is <strong>BoardMenuFragment.java</strong>, my Fragment java file :</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_board_menu, container, false);
      setupSearchView(view);
  
      // LISTVIEW
      // TODO This view is an example, don't forget to delete it
      values = new ArrayList&lt;&gt;();
      values.add("pomme");
      values.add("poire");
      values.add("banane");
      values.add("cerise");
      values.add("citron");
      adapter = new ArrayAdapter&lt;&gt;(getActivity(), android.R.layout.simple_expandable_list_item_1, android.R.id.text1, values);
      board_listView.setAdapter(adapter);
  
      return view;
  }
  
  private void setupSearchView(View view) {
      SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
      final SearchView searchView = (SearchView) view.findViewById(R.id.searchView);
      SearchableInfo searchableInfo = searchManager.getSearchableInfo(getActivity().getComponentName());
      searchView.setSearchableInfo(searchableInfo);
  }
  </code></pre>
  
  <p>But I have an exception which is :</p>
  
  <pre><code> java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.SearchView.setSearchableInfo(android.app.SearchableInfo)' on a null object reference
  </code></pre>
  
  <p>So my question is : is it possible to use <strong>SearchView</strong> in <strong>Fragment</strong> using <strong>SearchManager</strong> and <strong>SearchableInfo</strong> because I tried to do it using setOnQueryTextListener and it works but I don't think that is the best way to do it because I saw a lot of tutorials where you create a SearchableActivity...</p>