title: How can I show a new Fragment within a single tab?
body: <p>I am creating a three tabs that contains one fragment each now I want to replace the first Tab's Fragment with a new Fragment within the same Tab. How can I do that with the tab remaining the same? </p>
  
  <p><strong>My Code -</strong></p>
  
  <p><strong>Tab_Widget.java</strong></p>
  
  <pre><code>    public class Tab_Widget extends TabActivity {
  
              TabHost tabHost; 
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.tab_host);
  
              tabHost = getTabHost();
  
              tabHost.addTab(tabHost.newTabSpec("Tab1")
                  .setIndicator("Tab1")
                  .setContent(new Intent().setClass(this, main_activity.class)));
  
              tabHost.addTab(tabHost.newTabSpec("Tab2")
                  .setIndicator("Tab2")
                  .setContent(new Intent().setClass(this, second_activity.class)));
  
              tabHost.addTab(tabHost.newTabSpec("Tab3")
                      .setIndicator("Tab3")
                      .setContent(new Intent().setClass(this, third_activity.class)));
  
              tabHost.setCurrentTab(0);
          }
       }
  </code></pre>
  
  <hr>
  
  <p><strong>main_activity.java</strong></p>
  
  <pre><code>public class main_activity extends FragmentActivity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.mainfragment);
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>main_fragment.java</strong></p>
  
  <pre><code>public class main_fragment extends Fragment
  {
      LinearLayout mLayout;
      Button mButton;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          mLayout = (LinearLayout) inflater.inflate(R.layout.main_view, null);
          mButton = (Button) mLayout.findViewById(R.id.btn);
          mButton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  Fragment mFragment = new third_fragment_view();
                  FragmentTransaction ft = getFragmentManager().beginTransaction();
  //              ft.replace(R.id.Maincontainer, mFragment);
                  ft.replace(R.id.main_fragment, mFragment);
                  ft.addToBackStack(null);
                  ft.commit();
              }
          });
          return mLayout;
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>My XML</strong></p>
  
  <p><strong>mainfragment.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/Maincontainer"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;fragment
    android:name="com.fragment.main_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main_fragment"&gt;
  &lt;/fragment&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>By, this the Fragment is getting called no doubt, but its overlapping the previous Fragment.</p>