«

Fragment嵌套时注意点

时间:2024-3-2 17:50     作者:韩俊     分类: Android


final public FragmentManager getChildFragmentManager()

Return a private FragmentManager for placing and managing Fragments
inside of this Fragment.

You are attempting to use fragments nested within other fragments, by way of your FragmentTabHost.

In your StatisticsTab fragment, change this:

mTabHost.setup(getActivity(), getFragmentManager(), R.id.realtabcontent);

to this:

mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

Then, make sure to use the parent FragmentManager to commit the main fragment change, by changing getFragmentManager() to getActivity().getSupportFragmentManager() inside BreweryStatistics.onArticleSelected().

当Activity中嵌套FragmentContainer,而FragmentContainer中又嵌套FragmentSon时,注意应该使用getChildFragmentManager!!!
如:
在FragmentContainer中,有:

mPagerAdapter = new PagerAdapter(getChildFragmentManager());

而PagerAdapter中有FragmentSon

参考:
http://stackoverflow.com/questions/7338823/viewpager-recursive-entry-to-executependingtransactions

http://stackoverflow.com/questions/22150950/recursive-entry-to-executependingtransactions

标签: android

热门推荐