android.support.v4.app.FragmentPagerAdapter Java Examples

The following examples show how to use android.support.v4.app.FragmentPagerAdapter. 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 Project: fangzhuishushenqi   Author: Cinaly   File: SubjectBookListActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.subject_tabs));

    mTabContents = new ArrayList<>();
    mTabContents.add(SubjectFragment.newInstance("", 0));
    mTabContents.add(SubjectFragment.newInstance("", 1));
    mTabContents.add(SubjectFragment.newInstance("", 2));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #2
Source Project: fangzhuishushenqi   Author: Cinaly   File: BookDetailCommunityActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.bookdetail_community_tabs));

    mTabContents = new ArrayList<>();
    mTabContents.add(BookDetailDiscussionFragment.newInstance(bookId));
    mTabContents.add(BookDetailReviewFragment.newInstance(bookId));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #3
Source Project: fangzhuishushenqi   Author: Cinaly   File: SubCategoryListActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.sub_tabs));

    mPresenter.attachView(this);
    mPresenter.getCategoryListLv2();

    mTabContents = new ArrayList<>();
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.NEW));
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.HOT));
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.REPUTATION));
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.OVER));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #4
Source Project: fangzhuishushenqi   Author: Cinaly   File: SubRankActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.sub_rank_tabs));

    mTabContents = new ArrayList<>();
    mTabContents.add(SubRankFragment.newInstance(week));
    mTabContents.add(SubRankFragment.newInstance(month));
    mTabContents.add(SubRankFragment.newInstance(all));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #5
Source Project: MVVM-JueJin   Author: fashare2015   File: LoopPagerAdapterWrapper.java    License: MIT License 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    mViewPager = ((ViewPager) container);
    int realPosition =  (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter)
            ? position
            : toRealPosition(position);

    if (mBoundaryCaching) {
        ToDestroy toDestroy = mToDestroy.get(position);
        if (toDestroy != null) {
            mToDestroy.remove(position);
            return toDestroy.object;
        }
    }

    if(realPosition >= 0 && realPosition < getRealCount())
        return mAdapter.instantiateItem(container, realPosition);
    return null;
}
 
Example #6
Source Project: CircularViewPager   Author: sanyuzhang   File: CircularViewPager.java    License: MIT License 6 votes vote down vote up
public void setFragmentAdapter(@NonNull FragmentPagerAdapter adapter,
                               @NonNull FragmentManager fm) {
    mOriginalAdapter = adapter;
    mInternalFragmentPagerAdapter = new InternalFragmentPagerAdapter(fm);

    super.setAdapter(mInternalFragmentPagerAdapter);
    mCurrentPosition = mOriginalAdapter.getCount() * 3 / 2;
    super.setCurrentItem(mOriginalAdapter.getCount() * 3 / 2, false);

    addOnPageChangeListener(new SimpleOnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == SCROLL_STATE_IDLE) {
                int size = mOriginalAdapter.getCount();
                if (mCurrentPosition < size / 2 + size % 2) {
                    mInternalFragmentPagerAdapter.shiftIndex(false);
                } else if (mCurrentPosition > size * 2 + size / 2) {
                    mInternalFragmentPagerAdapter.shiftIndex(true);
                }
            }
        }
    });
}
 
Example #7
Source Project: CircularViewPager   Author: sanyuzhang   File: CircularViewPager.java    License: MIT License 6 votes vote down vote up
public void setFragmentAdapter(@NonNull FragmentPagerAdapter adapter,
                               @NonNull FragmentManager fm) {
    mOriginalAdapter = adapter;
    mInternalFragmentPagerAdapter = new InternalFragmentPagerAdapter(fm);

    super.setAdapter(mInternalFragmentPagerAdapter);
    mCurrentPosition = mOriginalAdapter.getCount() * 3 / 2;
    super.setCurrentItem(mOriginalAdapter.getCount() * 3 / 2, false);

    addOnPageChangeListener(new SimpleOnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == SCROLL_STATE_IDLE) {
                int size = mOriginalAdapter.getCount();
                if (mCurrentPosition < size / 2 + size % 2) {
                    mInternalFragmentPagerAdapter.shiftIndex(false);
                } else if (mCurrentPosition > size * 2 + size / 2) {
                    mInternalFragmentPagerAdapter.shiftIndex(true);
                }
            }
        }
    });
}
 
Example #8
Source Project: Compass   Author: tranleduy2000   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void createView() {
    CustomViewPager viewPager = (CustomViewPager) findViewById(R.id.view_pager);
    FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return 1;
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return new CompassFragment();
            }
            return null;
        }
    };
    viewPager.setAdapter(adapter);
    viewPager.setCurrentItem(1);
}
 
Example #9
Source Project: iGap-Android   Author: RooyeKhat-Media   File: ActivityMain.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
private void onSelectItem(int position) {
    FragmentPagerAdapter adapter = (FragmentPagerAdapter) mViewPager.getAdapter();

    if (adapter.getItem(position) instanceof FragmentMain) {

        findViewById(R.id.amr_ripple_search).setVisibility(View.VISIBLE);
        findViewById(R.id.am_btn_menu).setVisibility(View.GONE);
        arcMenu.setVisibility(View.VISIBLE);
        setFabIcon(R.mipmap.plus);
    } else if (adapter.getItem(position) instanceof FragmentCall) {

        findViewById(R.id.amr_ripple_search).setVisibility(View.GONE);
        findViewById(R.id.am_btn_menu).setVisibility(View.VISIBLE);
        setFabIcon(R.drawable.ic_call_black_24dp);
        arcMenu.setVisibility(View.VISIBLE);
    }

    if (arcMenu.isMenuOpened()) {
        arcMenu.toggleMenu();
    }

    arcMenu.fabMenu.show();
}
 
Example #10
Source Project: FragmentBackHandler   Author: ikidou   File: BackHandlerHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 将back事件分发给ViewPager中的Fragment,{@link #handleBackPress(FragmentManager)} 已经实现了对ViewPager的支持,所以自行决定是否使用该方法
 *
 * @return 如果处理了back键则返回 <b>true</b>
 * @see #handleBackPress(FragmentManager)
 * @see #handleBackPress(Fragment)
 * @see #handleBackPress(FragmentActivity)
 */
public static boolean handleBackPress(ViewPager viewPager) {
    if (viewPager == null) return false;

    PagerAdapter adapter = viewPager.getAdapter();

    if (adapter == null) return false;

    int currentItem = viewPager.getCurrentItem();
    Fragment fragment;
    if (adapter instanceof FragmentPagerAdapter) {
        fragment = ((FragmentPagerAdapter) adapter).getItem(currentItem);
    } else if (adapter instanceof FragmentStatePagerAdapter) {
        fragment = ((FragmentStatePagerAdapter) adapter).getItem(currentItem);
    } else {
        fragment = null;
    }
    return isFragmentBackHandled(fragment);
}
 
Example #11
Source Project: BookReader   Author: smuyyh   File: SubjectBookListActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.subject_tabs));

    mTabContents = new ArrayList<>();
    mTabContents.add(SubjectFragment.newInstance("", 0));
    mTabContents.add(SubjectFragment.newInstance("", 1));
    mTabContents.add(SubjectFragment.newInstance("", 2));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #12
Source Project: BookReader   Author: smuyyh   File: BookDetailCommunityActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.bookdetail_community_tabs));

    mTabContents = new ArrayList<>();
    mTabContents.add(BookDetailDiscussionFragment.newInstance(bookId));
    mTabContents.add(BookDetailReviewFragment.newInstance(bookId));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #13
Source Project: BookReader   Author: smuyyh   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    startService(new Intent(this, DownloadBookService.class));

    mTencent = Tencent.createInstance("1105670298", MainActivity.this);

    mDatas = Arrays.asList(getResources().getStringArray(R.array.home_tabs));
    mTabContents = new ArrayList<>();
    mTabContents.add(new RecommendFragment());
    mTabContents.add(new CommunityFragment());
    mTabContents.add(new FindFragment());

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #14
Source Project: BookReader   Author: smuyyh   File: SubCategoryListActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.sub_tabs));

    mPresenter.attachView(this);
    mPresenter.getCategoryListLv2();

    mTabContents = new ArrayList<>();
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.NEW));
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.HOT));
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.REPUTATION));
    mTabContents.add(SubCategoryFragment.newInstance(cate, "", gender, Constant.CateType.OVER));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #15
Source Project: BookReader   Author: smuyyh   File: SubRankActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initDatas() {
    mDatas = Arrays.asList(getResources().getStringArray(R.array.sub_rank_tabs));

    mTabContents = new ArrayList<>();
    mTabContents.add(SubRankFragment.newInstance(week));
    mTabContents.add(SubRankFragment.newInstance(month));
    mTabContents.add(SubRankFragment.newInstance(all));

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #16
Source Project: nono-android   Author: tianyuan168326   File: TestRoom.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_testroom);
    viewPager = (ViewPager)findViewById(R.id.view_pager);
    ballTabLayout =(BallTabLayout)findViewById(R.id.ball_tab_layout);

    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public Fragment getItem(int position) {
            return FragmentWithNum.newInstance(position);
        }
    });
    ballTabLayout.setupWithViewPager(viewPager);
}
 
Example #17
Source Project: umeng_community_android   Author: umeng   File: CommentTabFragment.java    License: MIT License 6 votes vote down vote up
@Override
protected void initWidgets() {

    mTitles = getResources().getStringArray(
            ResFinder.getResourceId(ResType.ARRAY, "umeng_comm_comments_tabs"));

    mIndicator = (ViewPagerIndicator) findViewById(ResFinder
            .getId("umeng_comm_comment_indicator"));
    mViewPager = (ViewPager) findViewById(ResFinder.getId("umeng_comm_comment_viewPager"));
    mIndicator.setTabItemTitles(mTitles);
    mAdapter = new FragmentPagerAdapter(getFragmentManager()) {

        @Override
        public int getCount() {
            return mTitles.length;
        }

        @Override
        public Fragment getItem(int pos) {
            return getFragment(pos);
        }
    };
    mViewPager.setAdapter(mAdapter);
    // 设置关联的ViewPager
    mIndicator.setViewPager(mViewPager, 0);
}
 
Example #18
Source Project: umeng_community_android   Author: umeng   File: TopicDetailActivity.java    License: MIT License 6 votes vote down vote up
private void initView() {
    mIndicator = (ViewPagerIndicator) findViewById(ResFinder.getId("indicator"));
    mViewPager = (ViewPager) findViewById(ResFinder.getId("viewPager"));
    mIndicator.setTabItemTitles(mTitles);
    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public int getCount() {
            return mTitles.length;
        }

        @Override
        public Fragment getItem(int pos) {
            return getFragment(pos);
        }
    };
    mViewPager.setAdapter(mAdapter);
    // 设置关联的ViewPager
    mIndicator.setViewPager(mViewPager, 0);
    // 初始化Header的控件跟数据
    initHeader();
    initTitle();
}
 
Example #19
Source Project: Android-ViewPagerIndicator   Author: hongyangAndroid   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initDatas()
{

	for (String data : mDatas)
	{
		VpSimpleFragment fragment = VpSimpleFragment.newInstance(data);
		mTabContents.add(fragment);
	}

	mAdapter = new FragmentPagerAdapter(getSupportFragmentManager())
	{
		@Override
		public int getCount()
		{
			return mTabContents.size();
		}

		@Override
		public Fragment getItem(int position)
		{
			return mTabContents.get(position);
		}
	};
}
 
Example #20
Source Project: MagicHeaderViewPager   Author: XAVlER-S   File: MagicHeaderViewPager.java    License: Apache License 2.0 6 votes vote down vote up
public void setPagerAdapter(FragmentPagerAdapter pagerAdapter) {
    if(!(pagerAdapter instanceof OuterPagerAdapter)) {
        throw new IllegalArgumentException("MagicHeaderViewPager's " +
                "FragmentPagerAdapter must implements interface OuterPagerAdapter!");
    }

    mPagerAdapter = pagerAdapter;

    ((OuterPagerAdapter)mPagerAdapter).setOuterScroller(this);

    if(mViewPager != null) {
        mViewPager.setAdapter(mPagerAdapter);
        if(mPagerSlidingTabStrip !=null) {
            mPagerSlidingTabStrip.setViewPager(mViewPager);
        }
    }
}
 
Example #21
Source Project: miappstore   Author: shipan2012   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {
    for (int i = 0; i < mDatas.size(); i++) {
        BaseViewPagerFragment vpFragment = VPFragmentFactory.newInstance().getVpFragment(i);
        if (vpFragment != null) {
            mTabContents.add(vpFragment);
        }
    }

    mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mTabContents.size();
        }

        @Override
        public Fragment getItem(int position) {
            return mTabContents.get(position);
        }
    };
}
 
Example #22
Source Project: AutoScrollViewPager   Author: angeldevil   File: MyActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);

    ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build();
    ImageLoader.getInstance().init(configuration);

    contentPager = findViewById(R.id.pager);
    contentPager.setOffscreenPageLimit(2);
    contentPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int i) {
            if (i == 0) {
                return new AutoScrollPagerFragment();
            }
            return TextFragment.newInstance("Fragment " + i);
        }

        @Override
        public int getCount() {
            return 3;
        }
    });
}
 
Example #23
Source Project: rxloader   Author: evant   File: MainActivityWithViewPager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewpager);

    ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
    pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int i) {
            return new MainFragment();
        }

        @Override
        public int getCount() {
            return 5;
        }
    });
}
 
Example #24
Source Project: AndroidTranslucentUI   Author: shadowwalkerzh   File: ForgetPwdActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_forget_pwd);
	myApp = (MyApplication) getApplication();
	tv1 = (TextView) findViewById(R.id.find_by_phone);
	tv2 = (TextView) findViewById(R.id.find_by_email);
	backTV = (TextView) findViewById(R.id.back);
	backTV.setOnClickListener(this);

	FragmentPagerAdapter adapter = new ForgetPwdFragmentAdapter(
			getSupportFragmentManager());
	viewPager = (ViewPager) findViewById(R.id.pager);
	viewPager.setAdapter(adapter);

	MyPagerIndicator underline_indicator = (MyPagerIndicator) findViewById(R.id.underline_indicator);
	underline_indicator.setViewPager(viewPager);

	tv1.setOnClickListener(this);
	tv2.setOnClickListener(this);
	changeTextColor(viewPager.getCurrentItem());
}
 
Example #25
Source Project: Common   Author: Dsiner   File: ToolBarActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initScrollTab(ScrollTab[] tabs, final ViewPager pager, List<String> titles) {
    final ArrayList<Fragment> fragments = new ArrayList<>();
    for (int i = 0; i < titles.size(); i++) {
        TabFragment fragment = new TabFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("index", i);
        fragment.setArguments(bundle);
        fragments.add(fragment);
    }
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public Fragment getItem(int arg0) {
            return fragments.get(arg0);
        }
    };
    pager.setOffscreenPageLimit(titles.size() - 1);
    pager.setAdapter(fragmentPagerAdapter);
    pager.addOnPageChangeListener(this);
    for (ScrollTab tab : tabs) {
        tab.setTitles(titles);
        tab.setNumber(1, "9", View.VISIBLE);//Set the red dot
        tab.setViewPager(pager);
        tab.setOnTabListener(new ScrollTab.OnTabListener() {
            @Override
            public void onChange(int index, View v) {
                pager.setCurrentItem(index, true);
            }
        });
    }
}
 
Example #26
Source Project: Common   Author: Dsiner   File: AbsAppCompatActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    mTitles = getTitles();
    mFragmentList = getFragments();
    if (mTitles.size() != mFragmentList.size()) {
        throw new RuntimeException("The size of titles is not equal size of fragments.");
    }
    mCurFragment = mFragmentList.get(0);
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        @Override
        public Fragment getItem(int arg0) {
            return mFragmentList.get(arg0);
        }
    };
    mViewPager.setOffscreenPageLimit(mFragmentList.size() - 1);
    mViewPager.setAdapter(fragmentPagerAdapter);
    mViewPager.addOnPageChangeListener(this);
    mScrollTab.setTitles(mTitles);
    mScrollTab.setViewPager(mViewPager);
    mScrollTab.setOnTabListener(new ScrollTab.OnTabListener() {
        @Override
        public void onChange(int position, View v) {
            mViewPager.setCurrentItem(position, true);
        }
    });
}
 
Example #27
Source Project: Common   Author: Dsiner   File: AbsPageFragmentActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    mTitles = getTitles();
    mFragmentList = getFragments();
    if (mTitles.size() != mFragmentList.size()) {
        throw new RuntimeException("The size of titles is not equal size of fragments.");
    }
    mCurFragment = mFragmentList.get(0);
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        @Override
        public Fragment getItem(int arg0) {
            return mFragmentList.get(arg0);
        }
    };
    mViewPager.setOffscreenPageLimit(mFragmentList.size() - 1);
    mViewPager.setAdapter(fragmentPagerAdapter);
    mViewPager.addOnPageChangeListener(this);
    mScrollTab.setTitles(mTitles);
    mScrollTab.setViewPager(mViewPager);
    mScrollTab.setOnTabListener(new ScrollTab.OnTabListener() {
        @Override
        public void onChange(int position, View v) {
            mViewPager.setCurrentItem(position, true);
        }
    });
}
 
Example #28
Source Project: Common   Author: Dsiner   File: AbsPageFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    mTitles = getTitles();
    mFragmentList = getFragments();
    if (mTitles.size() != mFragmentList.size()) {
        throw new RuntimeException("The size of titles is not equal size of fragments.");
    }
    mCurFragment = mFragmentList.get(0);
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {
        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        @Override
        public Fragment getItem(int arg0) {
            return mFragmentList.get(arg0);
        }
    };
    mViewPager.setOffscreenPageLimit(mFragmentList.size() - 1);
    mViewPager.setAdapter(fragmentPagerAdapter);
    mViewPager.addOnPageChangeListener(this);
    mScrollTab.setTitles(mTitles);
    mScrollTab.setViewPager(mViewPager);
    mScrollTab.setOnTabListener(new ScrollTab.OnTabListener() {
        @Override
        public void onChange(int position, View v) {
            mViewPager.setCurrentItem(position, true);
        }
    });
}
 
Example #29
Source Project: WanAndroid   Author: kangdp   File: BaseTabActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    FragmentPagerAdapter fragPagerAdapter = createFragPagerAdapter();
    if (fragPagerAdapter != null){
        viewPager.setAdapter(fragPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}
 
Example #30
Source Project: WanAndroid   Author: kangdp   File: TreeActivity.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
protected FragmentPagerAdapter createFragPagerAdapter() {
    btn_scroll_top.setVisibility(View.VISIBLE);
    btn_scroll_top.setOnClickListener(onScrollTopListener);
    viewPager.setOffscreenPageLimit(mTreeDatas.size());
    return new TreeFragPagerAdapter(getSupportFragmentManager(), mTreeDatas);
}