对以下代码有什么想法吗?在我的测试中,我发现替换的片段没有被破坏,并且在弹出返回堆栈时实例仍然存在。只是想验证这是否是使用片段事务的有效方法。
getSupportFragmentManager().beginTransaction().addToBackStack(null).replace(frame, fragmentB).commit();
我使用替换的原因是它会导致替换的片段运行其退出动画。
Fragment事务可以参考android设计器指南:http://developer.android.com/guide/components/fragments.html http://developer.android.com/guide/components/fragments.html
具体如下:
// Create new fragment and transaction
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
所以是的,您正在做的是替换片段的正确方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)