Java Code Examples for com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems#add()

The following examples show how to use com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From RemoteControlView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ViewPager viewPager = this.findViewById(R.id.viewpager);
    SmartTabLayout viewPagerTab = this.findViewById(R.id.viewpagertab);

    FragmentPagerItems pages = new FragmentPagerItems(this);
    pages.add(FragmentPagerItem.of("功能键", DemoFragment.class));
    pages.add(FragmentPagerItem.of("音量键", DemoFragment1.class));
    pages.add(FragmentPagerItem.of("播放键", DemoFragment.class));
    pages.add(FragmentPagerItem.of("数字键", DemoFragment.class));

    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);

    viewPager.setAdapter(adapter);
    viewPagerTab.setViewPager(viewPager);

    remoteControlView = this.findViewById(R.id.rcv);
}
 
Example 2
Source File: PageFragment.java    From ChangeTabLayout with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ViewPager mViewPager = (ViewPager) view.findViewById(R.id.vp);
    FragmentPagerItems pages = new FragmentPagerItems(getActivity());
    final int page = FragmentPagerItem.getPosition(getArguments());

    for (int i = 0; i < 5; i++) {
        Bundle bundle = new Bundle();
        bundle.putInt("page", page);
        bundle.putInt("position", i);
        pages.add(FragmentPagerItem.of(String.valueOf(i), DemoFragment.class, bundle));
    }
    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getChildFragmentManager(), pages); //Fragment嵌套Fragment时,要用getChildFragmentManager
    mViewPager.setAdapter(adapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPageMargin(30);
    final MainActivity mainActivity = (MainActivity) getActivity();
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            mainActivity.pageScrolled(page, position, positionOffset);
        }
    });
}
 
Example 3
Source File: MainActivity.java    From ChangeTabLayout with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mViewPager = (VerticalViewPager) this.findViewById(R.id.viewpager);
    mTabLayout = (ChangeTabLayout) this.findViewById(R.id.tabLayout);

    pages = new FragmentPagerItems(this);
    mViewPager.setOffscreenPageLimit(title.length);
    for (String titleResId : title) {
        pages.add(FragmentPagerItem.of(titleResId, PageFragment.class));
    }

    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);
    mViewPager.setAdapter(adapter);
    mTabLayout.setViewPager(mViewPager, icon, null);
    mTabLayout.setOnTabClickListener(new ChangeTabLayout.OnTabClickListener() {
        @Override
        public void onTabClicked(int position) {
            Log.d(TAG, "点击了" + position);
        }
    });

}