Viewpager未更新视图

时间:2017-10-04 14:22:42

标签: android android-viewpager

我在主活动中有一个底部导航,每个文件中有5个选项卡 每个片段中有5个选项卡 一切正常 但是当谈到其他Fragment底部导航时,viewpager没有更新

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    @Override
    public int getItemPosition(Object object){
        return PagerAdapter.POSITION_NONE;
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }

}



private void setupViewPager(ViewPager viewPager) {
    FrgPlayer.ViewPagerAdapter adapter = new FrgPlayer.ViewPagerAdapter(getFragmentManager());

    adapter.addFragment(new FrgJadval(), "a");
    adapter.addFragment(new FrgKholase(), "b");
    adapter.addFragment(new FrgAmar(), "c");
    adapter.addFragment(new FrgRokhdad(), "d");
    viewPager.setAdapter(adapter);

}

我不知道为什么不更新ViewPager的原因

1 个答案:

答案 0 :(得分:0)

尝试拨打notifyDataSetChanged()

    public void addFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
            notifyDataSetChanged();
        }