片段未在viewpager上加载

时间:2017-12-14 16:34:32

标签: android android-viewpager adapter

这是我的寻呼机适配器,我想通过viewpager和tablayout加载2个片段,但它只显示白屏。

public class HomeFragmentAdapter extends FragmentPagerAdapter {
    RelativeLayout headerLogo;

    public HomeFragmentAdapter(FragmentManager fm, RelativeLayout headerLogo) {
        super(fm);
        this.headerLogo = headerLogo;
    }

    @Override
    public Fragment getItem(int position) {
        //Returning the current tabs
        switch (position) {
            case 0:
                return new DoubleColumnMintsList();
            case 1:
                return new MyCircleMain();
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        return 2;
    }

}

这是内部活动:

viewPager = (ViewPager) view.findViewById(R.id.viewpager);
        HomeFragmentAdapter adapter = new HomeFragmentAdapter(getFragmentManager(), headerLogo);
        tabLayout = (TabLayout) view.findViewById(R.id.tabs);
        viewPager.setOffscreenPageLimit(2);
        viewPager.setAdapter(adapter);
        setupTabs(tabLayout);
        viewPager.setCurrentItem(0)

1 个答案:

答案 0 :(得分:1)

我也面临同样的问题,它解决了尝试使用这一行:

{{1}}