0

With a regular activity, you can use

// Display the fragment as the main content.
     getFragmentManager().beginTransaction()
             .replace(android.R.id.content, new SettingsFragment())
             .commit();

to replace your main content with another fragment. With the default swipable tabs activity in Eclipse, this just overlays your new fragment on top of the other fragments. Can I get the id of the entire ViewPager somehow and replace that instead of android.R.id.content? I want to replace all of the tabs with my new fragment.

Noumenon
  • 5,099
  • 4
  • 53
  • 73

1 Answers1

2

Normally fragments are inflated in FrameLayout for eg;- fragment_layout.xml

<FrameLayout android:id"@+id/framelayout" 
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>

In fragment class we set this layout as contentVIew as follows:

public class TestFragmentActivity extends FragmentActivity {

  @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.fragment_layout);

}

And we can put any fragments in this content frame Layout using replace() method in Activity:

getFragmentManager().beginTransaction()
             .replace(R.id.framelayout, new NewFragment())
             .commit();
Sreejith B Naick
  • 1,203
  • 7
  • 13
  • This makes a lot of sense and I'm pretty sure it's the correct answer. It doesn't actually work in the default Eclipse swipable tabs activity (the new fragment doesn't display), but I think that's probably due to http://stackoverflow.com/questions/7723964/replace-fragment-inside-a-viewpager/11974777#11974777 . I don't have time to deal with that right now. – Noumenon Jul 04 '13 at 23:03