title: Kotlin Android Navigation Drawer item onclick listener does not working
body: <p>I know this already asked many times, but in my case, I still don't get it. </p>
  
  <p>So I have a navigation drawer that set up in the <code>MainActivity.kt</code> (My app has many fragment that runs on this Activity). </p>
  
  <p><strong>MainActivity.kt</strong></p>
  
  <pre><code>class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
  
      lateinit var drawerLayout: DrawerLayout
      lateinit var binding: ActivityMainBinding
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          val binding = DataBindingUtil.setContentView&lt;ActivityMainBinding&gt;(this, R.layout.activity_main)
  
          drawerLayout = binding.drawerLayout
  
          //Get navigation controller of this App
          val navController = this.findNavController(R.id.myNavHostFragment)
  
          //Lock the Nav drawer
          drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
  
          NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)
          NavigationUI.setupWithNavController(binding.navView, navController)
      }
  
      override fun onNavigationItemSelected(item: MenuItem): Boolean {
          when (item.itemId) {
              R.id.nav_logout -&gt; {
                  Toast.makeText(this, "Publication", Toast.LENGTH_SHORT).show()
                  Log.i("MainActivity", "Sign out clicked!")
              }
              R.id.nav_messages -&gt; {
                  Toast.makeText(this, "Publication", Toast.LENGTH_SHORT).show()
              }
          }    
  
          binding.drawerLayout.closeDrawer(GravityCompat.START)
          return true
      }
  
      // Set up the back button on action bar
      override fun onSupportNavigateUp(): Boolean {
          val navController = this.findNavController(R.id.myNavHostFragment)
  
          return NavigationUI.navigateUp(navController, drawerLayout)
      }
  }
  </code></pre>
  
  <p>This is my Activity_main.xml</p>
  
  <p><strong>Activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;androidx.drawerlayout.widget.DrawerLayout
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/drawer_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fitsSystemWindows="true"
          tools:openDrawer="start"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"&gt;
  
              &lt;fragment
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/myNavHostFragment"
                  android:name="androidx.navigation.fragment.NavHostFragment"
                  app:navGraph = "@navigation/navigation"
                  app:defaultNavHost = "true"
                  /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;com.google.android.material.navigation.NavigationView
              android:id="@+id/nav_view"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_gravity="start"
              android:fitsSystemWindows="true"
              app:headerLayout="@layout/nav_header"
              app:menu="@menu/nav_drawer_menu"/&gt;
  
      &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  
  &lt;/layout&gt;
  </code></pre>
  
  <p>This is the menu layout for the navigation drawer: 
  <strong>nav_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&gt;
          &lt;item
              android:id="@+id/nav_profile"
              android:icon="@drawable/ic_person"
              android:title="Profile"/&gt;
          &lt;item
              android:id="@+id/nav_messages"
              android:icon="@drawable/ic_people"
              android:title="Messages"/&gt;
      &lt;/group&gt;
  
  
      &lt;item android:title="Account Settings"&gt;
          &lt;menu&gt;
              &lt;item
                  android:id="@+id/nav_logout"
                  android:title="Sign Out"/&gt;
          &lt;/menu&gt;
      &lt;/item&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/o1mNh.png" rel="nofollow noreferrer">This</a> is how the navigation drawer looks like.</p>
  
  <p>Am I missing something ? If there's anything unclear let me know.</p>