1

I have a fragment with blow layout that called Menu:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button android:id="@+id/button"/>
    <TableLayout android:id="@+id/tableLayout"/>

</TableLayout>
  1. I added it into my MainActivity

  2. That Menu fragment adds another Menu fragment into its TableLayout:

    fragmentManager.beginTransaction().add(R.id.tableLayout, new Menu()).commit()
    
  3. Now the second Menu want to add some fragments into itself TableLayout

    fragmentManager.beginTransaction().add(R.id.tableLayout, new MyFragment()).commit()
    

But that fragment adds in the first Menu.


How can I add a fragment into the second Menu fragment?

Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
golkarm
  • 1,021
  • 1
  • 11
  • 22

1 Answers1

0

@Gordak Fragment Inside Fragment

get your FragmentManager by using getChildFragmentManager() not by getFragmentManager() or getSupportFragmentManager()

Community
  • 1
  • 1
golkarm
  • 1,021
  • 1
  • 11
  • 22