Trying to add a fragment to my fragment container FrameLayout

前端 未结 3 2011
难免孤独
难免孤独 2020-12-18 17:45

I have created an xml file called editor.xml which contains a FrameLayout. In my main activity I am trying to add my custom fragment to my FrameLayout.

The error I r

相关标签:
3条回答
  • 2020-12-18 18:44

    You forgot to commit() your transaction.

    0 讨论(0)
  • 2020-12-18 18:48

    add commit() like this

     getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFrag).commit();
    
    0 讨论(0)
  • 2020-12-18 18:52

    You also forgot to call the addtoBackStack() method, otherwise your app closes when you hit the back button.

    0 讨论(0)
提交回复
热议问题