[ACCEPTED]-Trying to add a fragment to my fragment container FrameLayout-android-framelayout

Accepted answer
Score: 33

You forgot to commit() your transaction.

0

Score: 5

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

Score: 5

add commit() like this

 getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFrag).commit();

0

Score: 0
 1-   //Add fragment container in xml file
    
    <androidx.fragment.app.FragmentContainerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_container_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    </androidx.fragment.app.FragmentContainerView>


2-  //Implementation of BackStack

        fragmentTransaction.setReorderingAllowed(true);
        fragmentTransaction.addToBackStack("name");

0

More Related questions