Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
912334508 opened this issue Jan 26, 2024 · 0 comments

Comments

@912334508
Copy link

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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant