TabLayout中间选项卡未显示

时间:2016-07-22 12:46:41

标签: android android-fragments android-tablayout

我有一个带有片段的tablayout,由于某种原因,我的中间标签没有显示任何信息。 我收到了这条警告信息

/FragmentManager: moveToState: Fragment state for PlaceholderFragment{7ad7d52 #3 id=0x7f0d009a android:switcher:2131558554:2} not updated inline; expected state 3 found 2

在做了一些谷歌搜索之后,我遇到了这个问题: https://code.google.com/p/android/issues/detail?id=202037

不幸的是,他们在那个问题上说它不应该影响视图,只是一个警告,但是我没有显示视图。

这是我对tablayout的创建:

public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        switch (getArguments().getInt(ARG_SECTION_NUMBER)) {
            case 1:
                View rootView = inflater.inflate(R.layout.fragment_workout_days, container, false);
                TextView textView = (TextView) rootView.findViewById(R.id.section_label);
                textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
                return rootView;
            case 2: View rootView2 = inflater.inflate(R.layout.fragment_sub_page1, container, false);
                TextView textView2 = (TextView) rootView2.findViewById(R.id.section_label2);
                textView2.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
                return rootView2;
            case 3:
                View rootView3 = inflater.inflate(R.layout.fragment_sub_page2, container, false);
                TextView textView3 = (TextView) rootView3.findViewById(R.id.section_label3);
                textView3.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
                return rootView3;
            default: View rootView4 = inflater.inflate(R.layout.fragment_workout_days, container, false);
                TextView textView4 = (TextView) rootView4.findViewById(R.id.section_label);
                textView4.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
                return rootView4;
        }

谢谢!

0 个答案:

没有答案