title: Bottom navigation bar listener not working
body: <p>So i just got started with android development a couple weeks ago, while trying to make navigation between two fragments with a bottom nav bar, for some reasons the click listener is just not working, no errors, no warnings, compiles no problem but it might be some logic problem? here's the code:</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          val fragmentHome = HomeFragment()
          val fragmentProfile = ProfileFragment()
  
          replaceCurrentFragment(fragmentHome)
  
          NavigationBarView.OnItemSelectedListener { item -&gt;
              when(item.itemId) {
                  R.id.page_home -&gt; {
                      Log.i(&quot;NavBar&quot;,&quot;Home pressed&quot;)
                      replaceCurrentFragment(fragmentHome)
                      true
                  }
                  R.id.page_profile -&gt; {
                      Log.i(&quot;NavBar&quot;,&quot;Profile pressed&quot;)
                      replaceCurrentFragment(fragmentProfile)
                      true
                  }
                  else -&gt; {
                      Log.i(&quot;NavBar&quot;,&quot;Error?&quot;)
                      false
                  }
              }
          }
      }
  
      private fun replaceCurrentFragment(fragment: Fragment) =
          supportFragmentManager.beginTransaction().apply {
              replace(R.id.flFragment, fragment)
              commit()
          }
  }
  </code></pre>
  <p>Layout:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;FrameLayout
          android:id=&quot;@+id/flFragment&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;0dp&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/bottom_navigation&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          app:labelVisibilityMode=&quot;selected&quot;
          android:id=&quot;@+id/bottom_navigation&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:menu=&quot;@menu/bottom_navigation_menu&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>Menu:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;item
          android:id=&quot;@+id/page_home&quot;
          android:icon=&quot;@drawable/ic_home&quot;
          android:title=&quot;Home&quot;/&gt;
      &lt;item
          android:id=&quot;@+id/page_profile&quot;
          android:icon=&quot;@drawable/ic_profile&quot;
          android:title=&quot;Profile&quot;/&gt;
  &lt;/menu&gt;
  </code></pre>
  <p>the main page does get initialized on the home fragment, but when i click the nav bar buttons, nothing happens so the problem is in that listener part, copy pasted from the docs yet it doesn't work.</p>
  <p>i also have a bug where the layout editor doesn't show the nav bar contents, so my ide might be glitched? would appreciate any help.</p>