title: Androidx Navigation View - `setNavigationItemSelectedListener` Doesn't Work
body: <p><strong>What am I doing?</strong></p>
  
  <p>I have been trying to work with Androidx Navigation Drawer(<code>&lt;com.google.android.material.navigation.NavigationView&gt;</code>). I've read  the documentation <a href="https://material.io/develop/android/components/navigation-view/" rel="noreferrer">Here</a>, which says that for handling item selections we can use <code>setNavigationItemSelectedListener</code>. </p>
  
  <p><strong>Note:</strong> I am using JetPack's Navigation Component as well.</p>
  
  <p>Below is: <strong>main_activity.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;androidx.appcompat.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="@color/colorPrimary"
              android:theme="@style/ThemeOverlay.AppCompat.Dark" /&gt;
  
          &lt;fragment
              android:id="@+id/nav_host_fragment"
              android:name="androidx.navigation.fragment.NavHostFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:defaultNavHost="true"
              app:navGraph="@navigation/nav_graph" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;com.google.android.material.navigation.NavigationView
          android:id="@+id/navigationView"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true"
          app:menu="@menu/drawer_menu" /&gt;
  
  &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>Here is: <strong>MainActivity.java</strong></p>
  
  <pre><code>import android.os.Bundle;
  import android.view.MenuItem;
  import android.widget.Toast;
  
  import com.google.android.material.navigation.NavigationView;
  
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.appcompat.widget.Toolbar;
  import androidx.core.view.GravityCompat;
  import androidx.drawerlayout.widget.DrawerLayout;
  import androidx.navigation.NavController;
  import androidx.navigation.Navigation;
  import androidx.navigation.ui.NavigationUI;
  
  public class MainActivity extends AppCompatActivity {
  
      public Toolbar toolbar;
  
      public DrawerLayout drawerLayout;
  
      public NavController navController;
  
      public NavigationView navigationView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          setupNavigation();
  
      }
  
      // Setting Up One Time Navigation
      private void setupNavigation() {
  
          toolbar = findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          drawerLayout = findViewById(R.id.drawer_layout);
  
          navigationView = findViewById(R.id.navigationView);
          navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                  Toast.makeText(MainActivity.this, "Hello", Toast.LENGTH_SHORT).show();
                  return false;
              }
          });
  
          navController = Navigation.findNavController(this, R.id.nav_host_fragment);
  
          NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout);
  
          NavigationUI.setupWithNavController(navigationView, navController);
  
      }
  
      @Override
      public boolean onSupportNavigateUp() {
          return NavigationUI.navigateUp(drawerLayout, Navigation.findNavController(this, R.id.nav_host_fragment));
      }
  
      @Override
      public void onBackPressed() {
          if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
              drawerLayout.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Situation:</strong></p>
  
  <p>Everything displays fine, I get the <code>Drawer</code> at runtime, I also get the <code>Hamburger</code>, It works fine to display the <code>NavigationView</code> with the menu items. </p>
  
  <p>Below is: <strong>drawer_menu.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;group android:checkableBehavior="single"&gt;
  
          &lt;item
              android:id="@+id/first"
              android:icon="@mipmap/ic_launcher"
              android:title="First" /&gt;
  
          &lt;item
              android:id="@+id/second"
              android:icon="@mipmap/ic_launcher"
              android:title="Second" /&gt;
  
          &lt;item
              android:id="@+id/third"
              android:icon="@mipmap/ic_launcher"
              android:title="Third" /&gt;
  
      &lt;/group&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>On tapping the menu items, it does not respond to my click events, a.k.a <code>onNavigationItemSelected</code>. As you can see my <code>MainActivity.java</code>, the <code>Toast</code> does not appear neither any of the menu ids work inside switch.</p>
  
  <p>I've been trying many examples and different ways to get this done.</p>
  
  <p>Is there any way to make menu items respond to my select events?</p>
  
  <p>If you need any more details on this, please do comment below.</p>
  
  <p>Thank You so much for the Help.</p>