title: Bottom Navigation bar doesn't switch Fragments
body: <p>I (beginner) just coded a bottom navigation bar with help of this forum on Android Studio (API19) and it compiles start in the emulator, but I just can't figure out why it doesn't switch Fragments when you click the Items in the bar. For every Case in the method in Java I created a fragment without any special code in it. Despite that I implemented the design in the gradle in the beginning and added a floating button, but thats pretty much all I did.</p>
  
  <p>Thank you so much for any help!</p>
  
  <p>This is my Java Code</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      //Bottom Navigation Bar
      Fragment currentFragment = null;
      FragmentTransaction ft;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          //Bottom Navigation Bar
          ft = getSupportFragmentManager().beginTransaction();
          currentFragment = new HomeFragment();
          ft.replace(R.id.main_frame_layout, currentFragment);
          ft.commit();
  
          //Listener Bottom Navigation Bar
          BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation_bar);
          navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
      }
  
      // Method for Nav. Bar Listener
      private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  
              switch (item.getItemId()) {
  
                  case R.id.nav_home:
                      currentFragment = new HomeFragment();
                      ft = getSupportFragmentManager().beginTransaction();
                      ft.replace(R.id.main_frame_layout, currentFragment);
                      ft.commit();
                      return true;
  
                  case R.id.nav_overview:
                      currentFragment = new OverviewFragment();
                      ft = getSupportFragmentManager().beginTransaction();
                      ft.replace(R.id.main_frame_layout, currentFragment);
                      ft.commit();
                      return true;
  
                  case R.id.nav_charts:
                      currentFragment = new ChartsFragment();
                      ft = getSupportFragmentManager().beginTransaction();
                      ft.replace(R.id.main_frame_layout, currentFragment);
                      ft.commit();
                      return true;
  
                  case R.id.nav_targets:
                      currentFragment = new TargetsFragment();
                      ft = getSupportFragmentManager().beginTransaction();
                      ft.replace(R.id.main_frame_layout, currentFragment);
                      ft.commit();
                      return true;
              }
              return true;
          }
      };
  }
  </code></pre>
  
  <p>And this is my XML code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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"
      tools:context=".MainActivity"&gt;
  
      &lt;FrameLayout
          android:id="@+id/main_frame_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;android.support.design.widget.FloatingActionButton
          android:id="@+id/fab_add"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:clickable="true"
          android:layout_marginEnd="16dp"
          android:layout_marginBottom="72dp"
          android:src="@drawable/ic_add_white"
          android:layout_gravity="bottom|end"
          android:focusable="true"
          app:backgroundTint="@color/colorAccent"
          app:fabSize="normal"/&gt;
  
      &lt;/FrameLayout&gt;
  
      &lt;android.support.design.widget.BottomNavigationView
  
          android:id="@+id/navigation_bar"
          android:layout_width="match_parent"
          android:layout_height="56dp"
          android:layout_alignParentBottom="true"
          app:itemBackground="@color/colorPrimary"
          app:itemIconTint="@color/colorAccent"
          app:itemTextColor="@color/colorAccent"
          app:menu="@menu/navigation_items"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here is the menu file where I generated the navigation items but I think its unimportant</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;item
          android:id="@+id/nav_home"
          android:icon="@drawable/ic_home_white_24dp"
          android:title="@string/nav_home"
          android:enabled="true"/&gt;
      &lt;item
          android:id="@+id/nav_overview"
          android:icon="@drawable/ic_format_list_bulleted_white_24dp"
          android:title="@string/nav_overview"
          android:enabled="true"/&gt;
      &lt;item
          android:id="@+id/nav_charts"
          android:icon="@drawable/ic_insert_chart_white_24dp"
          android:title="@string/nav_charts"
          android:enabled="true"/&gt;
      &lt;item
          android:id="@+id/nav_targets"
          android:icon="@drawable/ic_monetization_on_white_24dp"
          android:title="@string/nav_targets"
          android:enabled="true"/&gt;
  
  &lt;/menu&gt;
  </code></pre>