title: RESOLVED I can't get access to menu in my fragment?
body: <hr>
  
  <p><h1>UPD:</h1> This link helped me resolve this issue
  <a href="https://riptutorial.com/android/example/19832/searchview-in-toolbar-with-fragment" rel="nofollow noreferrer">https://riptutorial.com/android/example/19832/searchview-in-toolbar-with-fragment</a></p>
  
  <hr>
  
  <p>I want to get access to menu items through <code>onOptionsItemSelected</code>, but it not called ever. I tried many ways and stopped on this solution, but it didn't help.</p>
  
  <h3>HomeFragment.java</h3>
  
  <pre><code>   public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
         Log.d(TAG, "onCreateView: ");
         View view = inflater.inflate(R.layout.fragment_home, container, false);
         ButterKnife.bind(this, view);
         setUpRecyclerView();
         setupAuthorsSelectionRV();
         setUpToolbar();
  
  
         HomeViewModel model = ViewModelProviders.of(this).get(HomeViewModel.class);
  
         disposable = model.getSongs()
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(songs -&gt; {
                     ((SongRVAdapter) songRV.getAdapter()).setSongList(songs);
                     songRV.getAdapter().notifyDataSetChanged();
                     Log.d(TAG, "UI updated! |Song list| - ");
                 }, throwable -&gt; {
                     Toast.makeText(getContext(),
                             "An error occurred - " + throwable,
                             Toast.LENGTH_SHORT).show();
                     Log.e(TAG, "Error while loading songs:\n", throwable);
                 }, () -&gt; Log.i(TAG, "Songs loaded!"));
  
         setHasOptionsMenu(true);
         return view;
     }
  </code></pre>
  
  <pre><code>@Override
      public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
          inflater.inflate(R.menu.toolbar_menu, menu);
          super.onCreateOptionsMenu(menu, inflater);
      }
  </code></pre>
  
  <pre><code>@Override
      public boolean onOptionsItemSelected(@NonNull MenuItem item) {
          Log.d(TAG, "onOptionsItemSelected: ");
          if (item.getItemId() == R.id.searchBtn) {
              Log.d(TAG, "onOptionsItemSelected: inside IF");
              ((SearchView) item.getActionView())
                      .setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                          @Override
                          public boolean onQueryTextSubmit(String query) {
                              Log.d(TAG, "onQueryTextSubmit: ");
                              Completable.fromAction(() -&gt; adapter.filter(query))
                                      .subscribeOn(Schedulers.io())
                                      .observeOn(AndroidSchedulers.mainThread())
                                      .subscribe(() -&gt; songRV.getAdapter().notifyDataSetChanged());
                              return true;
                          }
  
                          @Override
                          public boolean onQueryTextChange(String newText) {
                              Log.d(TAG, "onQueryTextChange: ");
                              Completable.fromAction(() -&gt; adapter.filter(newText))
                                      .subscribeOn(Schedulers.io())
                                      .observeOn(AndroidSchedulers.mainThread())
                                      .subscribe(() -&gt; songRV.getAdapter().notifyDataSetChanged());
                              return true;
                          }
                      });
  
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  </code></pre>
  
  <h3>fragment_home.xml</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/white"
      tools:context=".ui.homescreen.HomeFragment"&gt;
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:id="@+id/appBar"
          style="@style/wideStyle"
          android:background="@android:color/white"&gt;
  
  
          &lt;com.google.android.material.appbar.CollapsingToolbarLayout
              android:id="@+id/collapsingToolbar"
              android:layout_width="match_parent"
              android:layout_height="200dp"
              app:contentScrim="@android:color/transparent"
              app:expandedTitleMarginBottom="70dp"
              app:expandedTitleTextAppearance="@android:color/white"
              app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;
  
              &lt;androidx.constraintlayout.widget.ConstraintLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"&gt;
  
                  &lt;androidx.viewpager.widget.ViewPager
                      android:id="@+id/authorsSelectionsVP"
                      android:layout_width="wrap_content"
                      android:layout_height="100dp"
                      android:layout_marginTop="10dp"
                      app:layout_constraintBottom_toBottomOf="parent"
                      app:layout_constraintStart_toStartOf="parent"
                      app:layout_constraintTop_toBottomOf="@id/header" /&gt;
  
                  &lt;TextView
                      android:id="@+id/header"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginStart="10dp"
                      android:layout_marginTop="40dp"
                      android:ellipsize="end"
                      android:maxLines="1"
                      android:paddingBottom="5dp"
                      android:text="Авторская подборка"
                      android:textColor="@android:color/black"
                      android:textSize="25sp"
                      android:textStyle="bold"
                      app:layout_constraintBottom_toTopOf="@id/authorsSelectionsVP"
                      app:layout_constraintStart_toStartOf="parent"
                      app:layout_constraintTop_toTopOf="parent" /&gt;
  
              &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
          &lt;/com.google.android.material.appbar.CollapsingToolbarLayout&gt;
  
          &lt;androidx.appcompat.widget.Toolbar
              android:id="@+id/toolBar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="@android:color/transparent" /&gt;
  
  
  
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
  
      &lt;androidx.core.widget.NestedScrollView
          android:id="@+id/nestedScroll"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:clipToPadding="false"
          android:paddingBottom="100dp"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/allSongsLabel"&gt;
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
  
              &lt;TextView
                  android:id="@+id/allSongsLabel"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:paddingStart="15dp"
                  android:paddingBottom="12dp"
                  android:text="@string/all_songs"
                  android:textColor="@android:color/black"
                  android:textSize="20sp"
                  android:textStyle="bold"
                  app:layout_constraintBottom_toTopOf="@id/songRV"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent" /&gt;
  
              &lt;androidx.recyclerview.widget.RecyclerView
                  android:id="@+id/songRV"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  app:layout_constraintTop_toBottomOf="@id/allSongsLabel"
                  tools:listitem="@layout/song_item" /&gt;
  
  
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  
      &lt;/androidx.core.widget.NestedScrollView&gt;
  
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>What I should do to fix this issue if it on my side?</p>
  
  <hr>
  
  <p><h1>UPD:</h1> This link helped me resolve this issue
  <a href="https://riptutorial.com/android/example/19832/searchview-in-toolbar-with-fragment" rel="nofollow noreferrer">https://riptutorial.com/android/example/19832/searchview-in-toolbar-with-fragment</a></p>
  
  <hr>