title: Fragment not shown when clicking on Drawer
body: <p>I am creating a simple drawer layout in an android app:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.drawerlayout.widget.DrawerLayout
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:id=&quot;@+id/drawer_layout&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:fitsSystemWindows=&quot;true&quot;&gt;
      &lt;androidx.coordinatorlayout.widget.CoordinatorLayout
          android:id=&quot;@+id/coordinator_id&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
         &lt;FrameLayout
              android:id=&quot;@+id/main_content&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              app:layout_behavior=&quot;@string/appbar_scrolling_view_behavior&quot;/&gt;
         &lt;com.google.android.material.appbar.AppBarLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot;&gt;
              &lt;androidx.appcompat.widget.Toolbar
                  android:id=&quot;@+id/toolbar&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;?attr/actionBarSize&quot;
                  android:background=&quot;?attr/colorPrimaryDark&quot;
                  app:layout_scrollFlags=&quot;enterAlways|scroll&quot; /&gt;
           &lt;/com.google.android.material.appbar.AppBarLayout&gt;
       &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
       &lt;com.google.android.material.navigation.NavigationView
           android:id=&quot;@+id/nav_view&quot;
           android:layout_width=&quot;match_parent&quot;
           android:layout_height=&quot;wrap_content&quot;
           android:layout_gravity=&quot;left&quot;
           app:menu=&quot;@menu/main_mmm&quot;/&gt;
  
   &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  </code></pre>
  <p>The menu items are as follows:</p>
  <pre><code>&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;group android:checkableBehavior=&quot;single&quot;&gt;
          &lt;item
              android:id=&quot;@+id/nav_login&quot;
              android:title=&quot;Login&quot;/&gt;
          &lt;item
              android:id=&quot;@+id/nav_game&quot;
              android:title=&quot;Game&quot;/&gt;
          &lt;item
              android:id=&quot;@+id/nav_score&quot;
              android:title=&quot;Score&quot;/&gt;
          &lt;item
              android:id=&quot;@+id/nav_settings&quot;
              android:title=&quot;Settings&quot;
              android:checked=&quot;true&quot;/&gt;
          &lt;item
              android:id=&quot;@+id/nav_about&quot;
              android:title=&quot;About&quot;/&gt;
          &lt;item
              android:id=&quot;@+id/nav_help&quot;
              android:title=&quot;Help&quot;/&gt;
          &lt;item
              android:id=&quot;@+id/nav_videos&quot;
              android:title=&quot;Video&quot;/&gt;
      &lt;/group&gt;
   &lt;/menu&gt;
  </code></pre>
  <p>In the main activity's onCreate I do as follows:</p>
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
  
      supportActionBar?.setDisplayHomeAsUpEnabled(true)
      var drawerLayout = findViewById&lt;DrawerLayout&gt;(R.id.drawer_layout)
      mDrawerToggle = object : ActionBarDrawerToggle(this, drawerLayout,    R.string.drawer_open_content_description, R.string.drawer_closed_content_description) {
          override fun onDrawerClosed(view: View) {
              lateinit var newFragment:Fragment
  
              when(mSelectedItem) {
                  R.id.nav_settings -&gt; {
                      newFragment = SettingsFragment()
                      supportActionBar?.setTitle(&quot;Preferences&quot;)
                  }
              }
  
              supportFragmentManager.beginTransaction()
                  .replace(R.id.main_content, newFragment)
                  .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                  .commit();
  
              mSelectedItem = 0
          }
      }
  
      var navigationView = findViewById&lt;NavigationView&gt;(R.id.nav_view)
      navigationView.setNavigationItemSelectedListener {
          mSelectedItem = it.itemId
          it.setChecked(true)
          drawerLayout.closeDrawer(navigationView)
          true
      }
  
  }
  </code></pre>
  <p>When the navigationview listener is called it should save in mSelectedItem with one of the ids in the menu. But that does not happen. Instead an apparent random value is saved inside the mSelected item value. Can anyone please help ?</p>