title: Android BottomNavigationView OnNavigationItemSelectedListener Code Not Running
body: <p>I am working on an app to provide students with schedules, etc. for a school. I am trying to implement the BottomNavigationView in place of independent buttons at the bottom of each tab. I have completed extensive research to find out how to use the BottomNavigationView, and successfully created several test apps. However, I have thus far been unable to get the BottomNavigationView to work when implemented into previously written code. The view itself shows up, but the OnNavigationItemSelectedListener code is not running. Note: The amount of previously written code already in the app means that the best way (I think) to use the BottomNavigationView in this app is to switch to a different java class when one of the items in the BottomNavigationView is selected, and to have identical BottomNavigationViews in each of the four activities that I currently have.</p>
  
  <p>The onCreate of the MainActivity:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      findToday();
      BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.bottomnavschedule);
      navigation.bringToFront();
      navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(@NonNull MenuItem item) {
              switch (item.getItemId()) {
                  case R.id.schedule_tab:
                      return true;
                  case R.id.barcode_tab:
                      startActivity(new Intent(getApplicationContext(), barcodeActivity.class));
                      return true;
                  case R.id.contacts_tab:
                      startActivity(new Intent(getApplicationContext(), friendActivity.class));
                      return true;
                  case R.id.other_tab:
                      startActivity(new Intent(getApplicationContext(), otherActivity.class));
                      return true;
              }
              return false;
          }
      });
      new refreshSchedule().execute();
  </code></pre>
  
  <p>and the XML in activity_main:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      tools:context="com.fuady.ssa_app_redo1.MainActivity"
  
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:background="@mipmap/appbg4"&gt;
  
      &lt;RelativeLayout 
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
  
          android:layout_width="match_parent"
          android:layout_height="530dp"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"
          android:layout_alignParentTop="true"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          tools:context="com.fuady.ssa_app_redo1.MainActivity"&gt;
          &lt;Button
              android:id="@+id/todayButton"
              android:layout_width="100dp"
              android:layout_height="50dp"
              android:layout_above="@+id/dayScroller"
              android:layout_centerInParent="true"
              android:onClick="todayButtonFunction"
              android:text="Today"
              android:textSize="12dp" /&gt;
  
          &lt;Button
              android:id="@+id/previousDayButton"
              android:layout_width="100dp"
              android:layout_height="50dp"
              android:layout_above="@id/dayScroller"
              android:layout_marginRight="20dp"
              android:layout_toLeftOf="@+id/todayButton"
              android:onClick="previousDay"
              android:text="Previous Day"
              android:textSize="12dp" /&gt;
  
          &lt;Button
              android:id="@+id/nextDayButton"
              android:layout_width="100dp"
              android:layout_height="50dp"
              android:layout_above="@id/dayScroller"
              android:layout_marginLeft="20dp"
              android:layout_toRightOf="@+id/todayButton"
              android:onClick="nextDay"
              android:text="Next Day"
              android:textSize="12dp" /&gt;
  
          &lt;ListView
              android:id="@+id/listView"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_above="@+id/todayButton"
              android:layout_alignParentEnd="true"
              android:layout_alignParentRight="true"
              android:layout_below="@+id/button19"
              android:layout_marginTop="15dp" /&gt;
  
          &lt;TextView
              android:id="@+id/textView"
              android:layout_width="150dp"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_alignParentStart="true"
              android:layout_alignParentTop="true"
              android:layout_marginTop="2dp"
              android:textColor="#ffffff"
              android:textSize="16dp" /&gt;
  
          &lt;ImageView
              android:id="@+id/button19"
              android:layout_width="40dp"
              android:layout_height="40dp"
              android:layout_alignParentRight="true"
              android:layout_alignParentTop="true"
              android:layout_gravity="bottom|right"
              android:layout_marginEnd="9dp"
              android:layout_marginRight="9dp"
              android:background="@android:color/transparent"
              android:onClick="editSchedule"
              android:src="@drawable/editicon" /&gt;
  
  
          &lt;SeekBar
              android:id="@+id/dayScroller"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:layout_alignParentLeft="true"
              android:layout_centerHorizontal="true"
  
              android:layout_marginBottom="2dp" /&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;android.support.design.widget.BottomNavigationView
          android:id="@+id/bottomnavschedule"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          app:itemIconTint="@color/colorPrimary"
          app:menu="@menu/bottom_nav_resource" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My menu file for the BottomNavigationView (named bottomnavresource):</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/schedule_tab"
          android:title="Schedule"
          android:icon="@drawable/shedules"
          /&gt;
      &lt;item
          android:id="@+id/barcode_tab"
          android:title="Barcode"
          android:icon="@drawable/barcodeicon"
          /&gt;
      &lt;item
          android:id="@+id/contacts_tab"
          android:title="Contacts"
          android:icon="@drawable/friend"
          /&gt;
      &lt;item
          android:id="@+id/other_tab"
          android:title="More"
          android:icon="@drawable/other"
          /&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>I have not yet attempted to implement the BottomNavigationView into any of the other tabs because it does not work in this tab. I have also created another program with nearly identical BottomNavigationView code (none of the other code specifically for this app) as a test, and it worked perfectly. I have changed many things around many times, and still, when any tab on the BottomNavigationView is clicked, the tab becomes selected but the activity does not switch.</p>
  
  <p>Thank you for the help.</p>