关于fragment嵌套fragment时,报Recursive entry to executePendingTransactions
错误指向语句为: viewPager.setAdapter();
造成此原因是fragment嵌套fragment时,在子fragment中实例化适配器时传入父fragment。例如:
public class SectionsPagerAdapter extends FragmentPagerAdapter { String[] tabTitle = {"1","2",3","4"}; public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return new CartoonClassifyFragment(); } @Override public int getCount() { return tabTitle.length; } @Override public CharSequence getPageTitle(int position) { return tabTitle[position]; } }
实例化:SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
当中的构造参数传入getFragmentManager()应更改为getChildFragmentManager()
或
把SectionsPagerAdapter的构造函数中更改为
public SectionsPagerAdapter(Fragment fm) { super(fm.getChildFragmentManager()); }
上述方法就可以解决Recursive entry to executePendingTransactions的错误了;
部分android-support-v4.jar取不到getChildFragmentManager()方法,更新下该包即可。贴上个下载地址:http://download.csdn.net/detail/l900919zc/8168391