title: Android - Call a fragment inside tab
body: <p>I try to create an application that has two pages. First page is a tabbed page and second page is a detail page.</p>
  
  <p>I create a tapped page using <a href="http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/" rel="nofollow noreferrer">this guide</a>. I have a mainactivity that contains view pager and 3 tabs(<code>Tab1, Tab2, Tab3</code>). Tab3 contains a button to navigate detail page. Each tab has own .java(extends Fragment) and  .xml file. I edit fragmentThree.xml layout : </p>
  
  <pre><code>&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="match_parent"
  android:id="@+id/fragmentThree"]&gt;
  
  &lt;Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/goToDetail"
      android:text="GO TO DETAIL" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>I create a new fragment for detail page. I set onclick method inside of Tab3.java;</p>
  
  <pre><code>goToDetail.setOnClickListener(new View.OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
  
              FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
              FragmentTransaction transaction = fragmentManager.beginTransaction();
              transaction.replace(R.id.mainActivity, new Detail());
              transaction.commit();
          }
      });
  </code></pre>
  
  <p>When I press the button, it doesn't do anything. I don't replace the fragment.</p>