title: Android Fragment not replacing UI from Activity
body: <p>I am currently building an android application that uses a navigation drawer. When the user selects an item from the drawer, a fragment is created that corresponds to the item selected. For example, if the user selects the contacts item from the navigation drawer, the UI should change from the dashboard, to the contacts layout.</p>
  
  <p>I am successfully creating fragments, however the Fragment retains the calenderView from my dashboard.</p>
  
  <p>Here is the dashboard layout:</p>
  
  <p><a href="https://i.stack.imgur.com/puHOy.png" rel="nofollow noreferrer">Here is the Dashboard layout</a></p>
  
  <p>Here is the layout once the user selects timer from the navigation drawer
  <a href="https://i.stack.imgur.com/o8GsN.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>The problem is that the calenderView remains when the fragment is inflated. Ideally it would just be the "Timer Frag" Button that is visible in this fragment.</p>
  
  <p>Here is my mainActivity code:</p>
  
  <pre><code>//Fragments will be inflated through this method.
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
  
      Fragment fragment = null;
  
      // Handle navigation view item clicks here.
      int id = item.getItemId();
  
      if (id == R.id.nav_patient) {
          fragment = new Patient_Fragment();
          // Handle the camera action
      } else if (id == R.id.nav_timer) {
          fragment = new Timer_Fragment();
  
      } else if (id == R.id.nav_reminders) {
  
      } else if (id == R.id.nav_contacts) {
  
      } else if (id == R.id.nav_account) {
  
      } else if (id == R.id.nav_about) {
  
      }
  
      if(fragment !=null)
      {
          FragmentManager fragmentManager = getSupportFragmentManager();
          FragmentTransaction ft = fragmentManager.beginTransaction();
  
          ft.replace(R.id.dashboardArea, fragment);
          ft.commit();
      }
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(GravityCompat.START);
      return true;
  }
  </code></pre>
  
  <p>Here is my timer Fragment:</p>
  
  <pre><code>public class Timer_Fragment extends Fragment {
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         return inflater.inflate(R.layout.fragment_timer, null);
      }
  
      @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
      }
  }
  </code></pre>
  
  <p>Here is the fragment XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 
  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:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;Button
      android:id="@+id/timerFrag"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginTop="8dp"
      android:text="Timer Frag"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.181" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is the dashboard XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout 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"
  android:id="@+id/dashboardArea"
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context="com.example.a517086.carefree.MainActivity"
  tools:showIn="@layout/app_bar_main"&gt;
  
     &lt;CalendarView
      android:id="@+id/calendarView2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" /&gt;
     &lt;/FrameLayout&gt;
  </code></pre>