zoukankan      html  css  js  c++  java
  • 【Android】 java.lang.IllegalStateException: Recursive entry to executePendingTransactions

    在Fragment里面添加Viewpager,Viewpager由多个Fragment组成

    "引——没有拼命的干劲,怎能有精彩的结果!"

    java.lang.IllegalStateException: Recursive entry to executePendingTransactions
    找到发送错误的地方是viewpager.setAdapter()处。

    我的应用场景是: 嵌套使用Fragment使用,最外层使用了一个第三方的库,里面使用FragmentActivity,每个Fragment中又使用ViewPager再嵌套Fragment

    解决方法:嵌套Fragment设置PageAdapter时要使用getChildFragmentManager。

    New version of Support Library v4 (or Android 4.2, ofcourse) resolve this problem much simply. For do this, simply do constructor of your custom FragmentPagerAdapter like this:

    public CustomFragmentPagerAdapter(android.support.v4.app.Fragment fragment)
    {
        super(fragment.getChildFragmentManager());
        // write your code here
    }

    This work because new Android version approve using nested Fragments

    我这里没有修改CustomFragmentPagerAdapter,而是新建CustomFragmentPagerAdapter对象时使用参数改为this.getChildFragmentManager();

    adapter = new TabPageIndicatorAdapter(this.getChildFragmentManager()); 
    
    TabPageIndicatorAdapter类内容不变:
     /**
    	 * ViewPager
    	 * @author liwenjin
    	 *
    	 */
        class TabPageIndicatorAdapter extends FragmentPagerAdapter {
           
        	public TabPageIndicatorAdapter(FragmentManager  fm) {
                super(fm);
                
            }
    
            @Override
            public Fragment getItem(int position) {
                Fragment fragment = new ItemFragment();  
                Bundle args = new Bundle();  
                args.putString("arg", TITLE[position]);  
                fragment.setArguments(args);  
                return fragment;
            }
    
            @Override
            public CharSequence getPageTitle(int position) {
                return TITLE[position % TITLE.length];
            }
    
            @Override
            public int getCount() {
                return TITLE.length;
            }
        }

    This is an article reprinted!
  • 相关阅读:
    SCILAB简介[z]
    UG OPEN API编程基础 2约定及编程初步
    Office 2003与Office 2010不能共存的解决方案
    UG OPEN API 编程基础 3用户界面接口
    NewtonRaphson method
    UG OPEN API编程基础 13MenuScript应用
    UG OPEN API编程基础 14API、UIStyler及MenuScript联合开发
    UG OPEN API编程基础 4部件文件的相关操作
    UG OPEN API编程基础 1概述
    16 UG Open的MFC应用
  • 原文地址:https://www.cnblogs.com/Lt-Java13/p/4402526.html
Copyright © 2011-2022 走看看