1

我正在使用ViewPager并且我正在如下getItem方法内部动态创建片段,我想避免在此方法内部重新创建,以便应用程序不会崩溃。FragmentStatePagerAdapterFragment

        @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.

        Fragment fragment = new Fragment();

        switch (position) {
        case 0:                 
            fragment = new CourseOverViewFragment();
            break;
        case 1:
            fragment = new CourseSchedueListFragment();
            break;
        case 2:
            fragment = new CourseSchedueListFragment();
            break;
        case 3: 
            fragment = new CourseNoteListFragment();
            break;
        case 4:             
            fragment = new ProjectListFragment();
            break;
        default:
            Log.i(StudyManagerDataSource.LOG_TAG, "default");
            break;

        }

        return fragment;

    }

我多么喜欢这个stackoverflow答案。但我无法 在方法内分配标签getItem

谢谢!

4

0 回答 0