-3

I have an activity which has two fragments

When I launch the app, I want the fragment one to be displayed.

What code should I have in my MainActivity to do so?

Alex
  • 1
  • 4

2 Answers2

0

Write following code in you activity's onCreate() method

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    FragmentOne fragmentOne = new FragmentOne();
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.content_frame, fragmentOne, "fragmentOne")
            .addToBackStack("fragmentOne")
            .commit();
}
Krishna Meena
  • 5,693
  • 5
  • 32
  • 44
0

Without having any additional information, I can say that FragmentManager has a hide and show function that may be helpful during activities.