在Fragment3中有子片段,如果我从Fragment1打开Fragment3然后显示Fragment4但是现在我从fragment2打开fragment3然后片段4没有显示。
反之亦然,如果我从片段2打开片段3然后显示片段4,但如果我从片段1打开片段3,则片段4未显示。
添加片段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();
添加父片段的代码:
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();
答案 0 :(得分:0)
您需要使用
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
而不是
FragmentTransaction transaction = getFragmentManager().beginTransaction();
添加子片段时。 您可以参考this link了解更多详情。