Skip to content

Fragment 中无法使用建议:SlidingTabLayout setViewPager 参数 FragmentActivity 换成 FragmentManager #557

@912334508

Description

@912334508

SlidingTabLayout 在Fragment 嵌套 Fragment 的时候无法使用!!!

/** 关联ViewPager,用于连适配器都不想自己实例化的情况 */
public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList fragments) {
if (vp == null) {
throw new IllegalStateException("ViewPager can not be NULL !");
}

    if (titles == null || titles.length == 0) {
        throw new IllegalStateException("Titles can not be EMPTY !");
    }

    this.mViewPager = vp;
    this.mViewPager.setAdapter(new InnerPagerAdapter(fa.getSupportFragmentManager(), fragments, titles));

    this.mViewPager.removeOnPageChangeListener(this);
    this.mViewPager.addOnPageChangeListener(this);
    notifyDataSetChanged();
}

重写修改为:
public void setViewPager(ViewPager vp, String[] titles, FragmentManager fa, ArrayList fragments) {
if (vp == null) {
throw new IllegalStateException("ViewPager can not be NULL !");
}

    if (titles == null || titles.length == 0) {
        throw new IllegalStateException("Titles can not be EMPTY !");
    }

    this.mViewPager = vp;
    this.mViewPager.setAdapter(new MSlidingTabLayout.InnerPagerAdapter(fa, fragments, titles));

    this.mViewPager.removeOnPageChangeListener(this);
    this.mViewPager.addOnPageChangeListener(this);
    notifyDataSetChanged();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions