我收到了这个错误。虽然我已经通过各种链接,但没有任何帮助。
已经在各种链接中提到getChildFragmentManager()
。
这是代码:
viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(viewPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setOnTabSelectedListener(this);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
viewPager.setOffscreenPageLimit(2);
class ViewPagerAdapter extends FragmentStatePagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position)
{
case 0: return new Fragment1();
case 1: return new UserFragment();
case 2: return new Fragment2();
}
return null;
}
@Override
public int getCount() {
return 3;
}
}