本文整理汇总了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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
示例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;
}
示例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();
}
};
}
示例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;
}
});
}
示例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();
}
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}