问题描述
- 安卓,null expection,说FragmentManagerImpl什么的,求解决
-
先上logcat:开发-安卓,null expection,说FragmentManagerImpl什么的,求解决-fragmentmanagerimpl">
估计和viewpager有关,下面上viewpager的布局:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:showIn="@layout/activity_main" tools:context=".MainActivity" android:id="@+id/drawerlayout"> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent"/> <ListView android:id="@+id/listview" android:layout_width="240dp" android:layout_height="match_parent" android:background="#3366cc"> </ListView> </android.support.v4.widget.DrawerLayout>
下面是FragmentPagerAdapter:
public class MyFragmentPagerAdapter extends FragmentPagerAdapter { List<Fragment> list; String[] titles; public Fragment getItem(int position) { return list.get(position); } public int getCount() { return list.size(); } MyFragmentPagerAdapter(FragmentManager fm,List<Fragment> list,String[] titles) { super(fm); this.list=list; this.titles=titles; } public String getTitle(int position) { return titles[position]; } }
MainActivity中和viewpager有关的部分:
listFragment=new ArrayList<Fragment>(); listFragment.add(f1); listFragment.add(f2); listFragment.add(f3); listFragment.add(f4); listFragment.add(f5); viewPager=(ViewPager)super.findViewById(R.id.viewpager); fragmentPagerAdapter=new MyFragmentPagerAdapter(getSupportFragmentManager(),listFragment,new String[]{"标签1","标签2","标签3","标签4","标签5"}); viewPager.setAdapter(fragmentPagerAdapter); tabLayout=(TabLayout)super.findViewById(R.id.tablayout); for(int i=0;i<5;i++) { tabLayout.addTab(tabLayout.newTab().setText("标签"+i)); } tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setupWithViewPager(viewPager);
求教怎么解决?
解决方案
http://blog.csdn.net/xiaoyitian0/article/details/46969059
时间: 2024-09-05 09:06:54