Rohit
Rohit

Reputation: 3408

Replacing Child Fragment but working only firsttime

enter image description here

In Fragment3 have child fragment, if i open Fragment3 from Fragment1 then Fragment4 is shown but now i open fragment3 from fragment2 then fragment 4 is not shown.

And vice-versa if i open Fragment 3 from Fragment 2 then Fragment4 is shown, but if i open Fragment 3 from Fragment1 then Fragment 4 is not shown.

Code to add Fragment 4:

    Fixture_H2h_frag fragment1=new Fixture_H2h_frag();
        Bundle b1 = new Bundle();
        b1.putBoolean("Show", true);
        //b.putString("RESULT", result);
        b1.putString("URL", Url);
        b1.putString("TYPE", "FORM");
        b1.putString("VisitorTeam1", matchlist.get(pos).getVisitor_image_url());
        b1.putString("LocalTeam1", matchlist.get(pos).getLocal_image_url());

        fragment1.setArguments(b1);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        transaction.replace(R.id.Inner_Fixture_Container, fragment1);
        transaction.addToBackStack(null);

        // Commit the transaction
        transaction.commit();

Code to add Parent Fragment:

 FixtureDescrption_Frag frag = new FixtureDescrption_Frag();
FragmentManager fm = contxt.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.add(R.id.fragment_place, frag);
        fragmentTransaction
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        if(addedtostack){
        fragmentTransaction.addToBackStack(contxt.getClass().getName());
        }
        fragmentTransaction.commit();

Upvotes: 0

Views: 203

Answers (1)

Akhil
Akhil

Reputation: 6697

You need to use

FragmentTransaction transaction = getChildFragmentManager().beginTransaction();

instead of

FragmentTransaction transaction = getFragmentManager().beginTransaction();

While adding child fragment. You can refer this link for more details.

Upvotes: 0

Related Questions