为什么标签和片段没有出现?

时间:2018-01-10 12:04:21

标签: android android-layout android-fragments android-tabs

出于某种原因,我的标签没有显示出来。 我的播放器主页活动应显示两个选项卡,命名配置文件团队,但它没有显示任何内容。并且没有显示任何错误。

OnCreate玩家主页活动

mainAppToolBar = (android.support.v7.widget.Toolbar) findViewById(R.id.mainAppBar);
    setSupportActionBar(mainAppToolBar);
    getSupportActionBar().setTitle("Player Home");

    playerTabLayout = (TabLayout) findViewById(R.id.playerMainTabs);
    playerViewPager = (ViewPager) findViewById(R.id.playerMainTabPager);

    playerSectionPageAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    playerViewPager.setAdapter(playerSectionPageAdapter);
    playerTabLayout.setupWithViewPager(playerViewPager);

章节页面适配器的代码

public class SectionPageAdapter extends FragmentPagerAdapter {
public SectionPageAdapter(FragmentManager fm) {
    super(fm);
}
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0:
            ProfileFragment profileFragment = new ProfileFragment();
            return profileFragment;
        case 1:
            TeamFragment teamFragment = new TeamFragment();
            return teamFragment;
        default:
            return null;
    }
}

@Override
public int getCount() { return 2;}
public CharSequence getPageTitle(int position) {
    switch (position) {
        case 0:
            return "Profile";
        case 1:
            return "Teams";
        default:
            return null;
    }
}}

请帮忙。

1 个答案:

答案 0 :(得分:0)

getCount()被覆盖,但我没有看到getPageTitle。我认为你错过了@override

    @Override
    public int getCount() { return 2;}

    @Override - add this
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "Profile";
            case 1:
                return "Teams";
            default:
                return null;
        }
    }}