当前位置: 首页>>代码示例>>Java>>正文


Java FragmentPagerAdapter类代码示例

本文整理汇总了Java中android.support.v4.app.FragmentPagerAdapter的典型用法代码示例。如果您正苦于以下问题:Java FragmentPagerAdapter类的具体用法?Java FragmentPagerAdapter怎么用?Java FragmentPagerAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FragmentPagerAdapter类属于android.support.v4.app包,在下文中一共展示了FragmentPagerAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:SubjectBookListActivity.java

示例2: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:BookDetailCommunityActivity.java

示例3: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:MainActivity.java

示例4: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:SubCategoryListActivity.java

示例5: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:SubRankActivity.java

示例6: initData

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@Override
protected void initData() {

    adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return WelcomeFragment.newInstance(position+"");
        }

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

    vp.setAdapter(adapter);

}
 
开发者ID:ZhouKanZ,项目名称:SweepRobot,代码行数:19,代码来源:WelcomeActivity.java

示例7: instantiateItem

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@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;
}
 
开发者ID:fashare2015,项目名称:MVVM-JueJin,代码行数:20,代码来源:LoopPagerAdapterWrapper.java

示例8: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
private void initDatas() {

        fragments.add(new ReciteFragment());
        fragments.add(new SocietyFragment());
        fragments.add(new MessageFragment());
        fragments.add(new MeFragment());

        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        };
    }
 
开发者ID:chenlindev,项目名称:beyondwords,代码行数:20,代码来源:MainActivity.java

示例9: onCreate

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewpager);

    viewPager = findViewById(R.id.viewPager);

    fragments = new ArrayList<>();
    fragments.add(ViewPagerFragment.newInstance());
    fragments.add(ViewPagerFragment.newInstance());
    fragments.add(ViewPagerFragment.newInstance());

    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return 3;
        }
    });
}
 
开发者ID:shucc,项目名称:Carousel,代码行数:25,代码来源:ViewPagerTestActivity.java

示例10: onCreate

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFragments.add(new TestFragment());
    mFragments.add(new TestFragment());
    setContentView(R.layout.activity_main2);
    ViewPager viewPager = findViewById(R.id.viewpager);
    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    });
}
 
开发者ID:QuincySx,项目名称:StatusLayout,代码行数:20,代码来源:Main2Activity.java

示例11: handleBackPress

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
/**
 * 将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);
}
 
开发者ID:yangchong211,项目名称:YCUtils,代码行数:24,代码来源:BackHandlerHelper.java

示例12: initDatas

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
private void initDatas() {
    mIndicator.setTitles(mTitles);

    for (int i = 0; i < mTitles.length; i++) {
        mFragments[i] = TabFragment.newInstance(mTitles[i]);
    }

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

        @Override
        public Fragment getItem(int position) {
            return mFragments[position];
        }

    };

    mViewPager.setAdapter(mAdapter);
    mViewPager.setCurrentItem(0);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:24,代码来源:CoordinatorLayoutActivity.java

示例13: initView

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
private void initView() {
    listFragment = new ArrayList<>();
    homeFragment = new HomeFragment();
    taskFragment = new TaskFragment();
    rankFragment = new RankFragment();
    meFragment = new MeFragment();
    listFragment.add(homeFragment);
    listFragment.add(taskFragment);
    listFragment.add(rankFragment);
    listFragment.add(meFragment);

    adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return listFragment.get(position);
        }

        @Override
        public int getCount() {
            return listFragment.size();
        }
    };
    viewPager.setAdapter(adapter);
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:25,代码来源:MainActivity.java

示例14: handleBackPress

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
/**
 * 将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);
}
 
开发者ID:ikidou,项目名称:FragmentBackHandler,代码行数:27,代码来源:BackHandlerHelper.java

示例15: initViews

import android.support.v4.app.FragmentPagerAdapter; //导入依赖的package包/类
private void initViews() {
    // Bottom bar
    BottomNavigationView bottomNavigationView = findById(this, bottom_navigation_view);
    bottomNavigationView.setOnNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.tab_iss_location:
                    contentViewPager.setCurrentItem(ISS_LOCATION_FRAGMENT_POSITION, false);
                    break;
                case R.id.tab_people_in_space:
                    contentViewPager.setCurrentItem(PEOPLE_IN_SPACE_FRAGMENT_POSITION, false);
                    break;
                case R.id.tab_iss_pass_times:
                    contentViewPager.setCurrentItem(ISS_PASS_TIMES_FRAGMENT_POSITION, false);
                    break;
            }
            return true;
        }
    });

    // ViewPager
    FragmentPagerAdapter mainPagerAdapter = new MainPagerAdapter(getSupportFragmentManager());
    contentViewPager.setAdapter(mainPagerAdapter);
}
 
开发者ID:imartinez,项目名称:SpaceMaterial,代码行数:26,代码来源:MainActivity.java


注:本文中的android.support.v4.app.FragmentPagerAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。