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 File: LoopPagerAdapterWrapper.java From MVVM-JueJin with MIT License | 6 votes |
@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 #2
Source File: MainActivity.java From Android-ViewPagerIndicator with Apache License 2.0 | 6 votes |
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 #3
Source File: ActivityMain.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
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 #4
Source File: MainActivity.java From Compass with Apache License 2.0 | 6 votes |
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 #5
Source File: BackHandlerHelper.java From FragmentBackHandler with Apache License 2.0 | 6 votes |
/** * 将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 #6
Source File: TopicDetailActivity.java From umeng_community_android with MIT License | 6 votes |
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 #7
Source File: MagicHeaderViewPager.java From MagicHeaderViewPager with Apache License 2.0 | 6 votes |
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 #8
Source File: CommentTabFragment.java From umeng_community_android with MIT License | 6 votes |
@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 #9
Source File: CircularViewPager.java From CircularViewPager with MIT License | 6 votes |
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 #10
Source File: CircularViewPager.java From CircularViewPager with MIT License | 6 votes |
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 #11
Source File: TestRoom.java From nono-android with GNU General Public License v3.0 | 6 votes |
@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 #12
Source File: SubRankActivity.java From BookReader with Apache License 2.0 | 6 votes |
@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 #13
Source File: SubCategoryListActivity.java From BookReader with Apache License 2.0 | 6 votes |
@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 #14
Source File: MainActivity.java From miappstore with Apache License 2.0 | 6 votes |
@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 #15
Source File: MainActivity.java From BookReader with Apache License 2.0 | 6 votes |
@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 #16
Source File: SubRankActivity.java From fangzhuishushenqi with Apache License 2.0 | 6 votes |
@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 #17
Source File: SubCategoryListActivity.java From fangzhuishushenqi with Apache License 2.0 | 6 votes |
@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 #18
Source File: BookDetailCommunityActivity.java From BookReader with Apache License 2.0 | 6 votes |
@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 #19
Source File: BookDetailCommunityActivity.java From fangzhuishushenqi with Apache License 2.0 | 6 votes |
@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 #20
Source File: SubjectBookListActivity.java From fangzhuishushenqi with Apache License 2.0 | 6 votes |
@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 #21
Source File: SubjectBookListActivity.java From BookReader with Apache License 2.0 | 6 votes |
@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 #22
Source File: MyActivity.java From AutoScrollViewPager with Apache License 2.0 | 6 votes |
@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 File: MainActivityWithViewPager.java From rxloader with Apache License 2.0 | 6 votes |
@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 File: ForgetPwdActivity.java From AndroidTranslucentUI with Apache License 2.0 | 6 votes |
@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 File: LoopPagerAdapterWrapper.java From SuperIndicator with Apache License 2.0 | 5 votes |
@Override public Object instantiateItem(ViewGroup container, int position) { 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; } } return mAdapter.instantiateItem(container, realPosition); }
Example #26
Source File: LoginActivity.java From BitkyShop with MIT License | 5 votes |
void setTabLayout() { TabLayout tabLayout = (TabLayout) findViewById(R.id.loginActivity_tabLayout); ViewPager viewPager = (ViewPager) findViewById(R.id.loginActivity_viewPager); //初始化各fragment LoginPhoneFragment loginPhoneFragment = new LoginPhoneFragment(); // LoginLegacyFragment loginLegacyFragment = new LoginLegacyFragment(); // loginLegacyFragment.setActivity(this); loginPhoneFragment.setActivity(this); //将fragment装进列表中 List<Fragment> fragmentList = new ArrayList<>(); fragmentList.add(loginPhoneFragment); // fragmentList.add(loginLegacyFragment); //将名称加载tab名字列表,正常情况下,我们应该在values/arrays.xml中进行定义然后调用 List<String> titleList = new ArrayList<>(); titleList.add("手机号一键登录"); // titleList.add("传统登录"); //设置TabLayout的模式 tabLayout.setTabMode(TabLayout.MODE_FIXED); //为TabLayout添加tab名称 tabLayout.addTab(tabLayout.newTab().setText(titleList.get(0))); // tabLayout.addTab(tabLayout.newTab().setText(titleList.get(1))); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentPagerAdapter fAdapter = new FindTabAdapter(fragmentManager, fragmentList, titleList); //viewpager加载adapter viewPager.setAdapter(fAdapter); //TabLayout加载viewpager tabLayout.setupWithViewPager(viewPager); }
Example #27
Source File: SampleTabsStyled.java From android-open-project-demo with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_tabs); FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager()); ViewPager pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator); indicator.setViewPager(pager); }
Example #28
Source File: JamMainTabbedActivity.java From jam-collaboration-sample with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_jam_main); pageAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { Class clss; switch(position) { case 0: clss = JamFeedWidgetFragment.class; break; case 1: clss = JamGroupsListRename.class; break; default: throw new RuntimeException("Invalid tab index: " + position); } return Fragment.instantiate(JamSDKDemoApp.getAppContext(), clss.getName()); } @Override public int getCount() { return 2; } }; viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(pageAdapter); }
Example #29
Source File: TimelinesActivity.java From twitter-kit-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pager); final FragmentManager fm = getSupportFragmentManager(); final FragmentPagerAdapter pagerAdapter = new TimelinePagerAdapter(fm, getResources()); final ViewPager viewPager = findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); final TabLayout tabLayout = findViewById(R.id.tab_layout); tabLayout.setupWithViewPager(viewPager); }
Example #30
Source File: FixedPagerAdapter.java From NetEasyNews with GNU General Public License v3.0 | 5 votes |
private String getFragmentTag(int viewId, int index) { try { Class<FragmentPagerAdapter> cls = FragmentPagerAdapter.class; Class<?>[] parameterTypes = { int.class, long.class }; Method method = cls.getDeclaredMethod("makeFragmentName", parameterTypes); method.setAccessible(true); String tag = (String) method.invoke(this, viewId, index); return tag; } catch (Exception e) { e.printStackTrace(); return ""; } }