(4.3.1.15.1)抽屉控件+NavigationLeftFragment的方案修改


原来为:

<fragment
                android:id="@+id/navigation_drawer_old"
                android:name="com.android.yunshi.fragment.NavigationLeftFragment"
                android:layout_width="@dimen/navigation_drawer_width"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:visibility="gone"
                tools:layout="@layout/fragment_navigation_drawer" />


mNavigationDrawerFragment = (NavigationLeftFragment) getSupportFragmentManager()
		//		.findFragmentById(R.id.navigation_drawer);
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
				(DrawerLayout) findViewById(R.id.yunshi_root));




这几天,收集到的回馈中,有大量错误这样就会出现错误: 

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.yunshi/com.android.yunshi.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099)
	at android.app.ActivityThread.access$600(ActivityThread.java:134)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4796)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:543)
	at dalvik.system.NativeStart.main(Native Method)


     原因就是,v4.fragment不支持<fragment>静态标签,部分型号的手机,会导致程序崩溃


解决方案:

mNavigationDrawerFragment=new NavigationLeftFragment();
		FragmentManager fragmentManager = getSupportFragmentManager();  
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();  
		fragmentTransaction.replace(R.id.navigation_drawer, mNavigationDrawerFragment);
		fragmentTransaction.commit();
		fragmentManager.executePendingTransactions();
		// Set up the drawer.  找到抽屉控件
		mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
				(DrawerLayout) findViewById(R.id.yunshi_root));


注意,一定要fragmentManager.executePendingTransactions();  立即提交事务

不然commit()总是在activity的UI完成后,才提交,这样你在Fragment中的getActivity()就会报错,因为是空





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值