本文整理汇总了Java中android.support.v4.app.FragmentStatePagerAdapter类的典型用法代码示例。如果您正苦于以下问题:Java FragmentStatePagerAdapter类的具体用法?Java FragmentStatePagerAdapter怎么用?Java FragmentStatePagerAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FragmentStatePagerAdapter类属于android.support.v4.app包,在下文中一共展示了FragmentStatePagerAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: correctFragmentsInTabs
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
@Test
public void correctFragmentsInTabs()
{
ActivityController activityController = Robolectric.buildActivity(TransactionActivity.class).create();
Activity activity = (Activity)activityController.get();
activityController.start();
activityController.resume();
final ViewPager viewPager = (ViewPager) activity.findViewById(R.id.pager);
assertNotNull(viewPager);
final FragmentStatePagerAdapter adapter = (FragmentStatePagerAdapter)viewPager.getAdapter();
assertNotNull(adapter);
assertEquals(2, adapter.getCount());
checkFragmentStatus(activity, 0);
checkFragmentStatus(activity, 1);
}
示例2: instantiateItem
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的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;
}
示例3: initPager
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void initPager() {
pager.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
recyclerView.setAdapter(null);
adapter = new FragmentStatePagerAdapter(getChildFragmentManager()) {
@Override
public int getCount() {
return playlistcount;
}
@Override
public Fragment getItem(int position) {
return PlaylistPagerFragment.newInstance(position);
}
};
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(3);
}
示例4: setupViews
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void setupViews(PhotoViewPager viewPager) {
final ArrayList<String> images = getIntent().getStringArrayListExtra(EXTRA_IMAGES);
if (images == null || images.isEmpty()) {
Log.e(TAG, "images is null ");
// TODO: 2017/11/15 show a error view
return;
}
FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int i) {
final String image = images.get(i);
return PhotoViewFragment.newInstance(image);
}
@Override
public int getCount() {
return images.size();
}
};
final int position = getIntent().getIntExtra(EXTRA_POSITION, 0);
viewPager.setAdapter(adapter);
viewPager.setCurrentItem((position >= images.size() || position <= 0) ? 0 : position);
}
示例5: handleBackPress
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的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);
}
示例6: handleBackPress
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的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);
}
示例7: checkFragmentStatus
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void checkFragmentStatus(final Activity activity, final int adapterItemIndex)
{
final ViewPager viewPager = (ViewPager) activity.findViewById(R.id.pager);
assertNotNull(viewPager);
final FragmentStatePagerAdapter adapter = (FragmentStatePagerAdapter)viewPager.getAdapter();
assertNotNull(adapter);
Fragment fragment = adapter.getItem(adapterItemIndex);
assertNotNull(fragment);
Bundle arguments = fragment.getArguments();
assertNotNull(arguments);
final int expectedTransactionType = (adapterItemIndex == 0) ?
DBHelper.TransactionDbIds.EXPENSE : DBHelper.TransactionDbIds.REVENUE;
assertEquals(expectedTransactionType, arguments.getInt("type"));
}
示例8: initFragmentAdapter
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void initFragmentAdapter() {
frameLayout=(FrameLayout) findViewById(R.id.fragHome);
statePagerAdapter=new FragmentStatePagerAdapter(getSupportFragmentManager()) {
public int getCount() {
return 4;
}
public Fragment getItem(int arg0) {
switch (arg0) {
case 0:
return new NewsFragment();
case 1:
return new HotgoodsFragment();
case 2:
return new ITcircleFragment();
case 3:
return new MineFragment();
default:
return null;
}
}
};
}
示例9: refreshFromOptionsMenu
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
@Override
protected void refreshFromOptionsMenu() {
super.refreshFromOptionsMenu();
/** this hack worked with FragmenPagerAdapter but not with FragmentStatePagerAdapter */
// Fragment currentFragment = getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pegel_data_pager + ":" + mPager.getCurrentItem());
Fragment currentFragment = (Fragment) ((FragmentStatePagerAdapter)mPagerAdapter).instantiateItem(mPager, mPager.getCurrentItem());
if(currentFragment != null ) {
switch (mPager.getCurrentItem()) {
case 0:
((PegelDataFragment) currentFragment).loadData(true);
break;
case 1:
((PegelDataDetailFragment) currentFragment).loadData(true);
break;
case 2:
((PegelDetailFragment) currentFragment).loadData(true);
break;
case 3:
((PegelMapFragment) currentFragment).loadData(true);
break;
}
}
}
示例10: onCreateView
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
// create ContextThemeWrapper from the original Activity Context with the custom theme
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.PagerIndicatorDefaultNewWithDivider);
// clone the inflater using the ContextThemeWrapper
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
// Inflate the layout for this fragment
View rootView = localInflater.inflate(R.layout.fragment_card_payment, container, false);
FragmentStatePagerAdapter adapter = new SavePayAdapter(getChildFragmentManager());
ViewPager pager = (ViewPager) rootView.findViewById(R.id.pager);
pager.setOffscreenPageLimit(options.size());
pager.setAdapter(adapter);
TabPageIndicator indicator = (TabPageIndicator) rootView.findViewById(R.id.indicator);
indicator.setViewPager(pager);
return rootView;
}
示例11: initViews
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void initViews() {
mViewPager.setAdapter(new FragmentStatePagerAdapter(
getSupportFragmentManager()) {
@Override
public int getCount() {
return VolleyUtil.mImages.size();
}
@Override
public Fragment getItem(int position) {
return BeautyFragment.newInstance(VolleyUtil.mImages.get(position)
.getUrl());
}
});
int positon = getIntent().getIntExtra(POSITION, 0);
mViewPager.setCurrentItem(positon);
}
示例12: onCreate
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pager);
final MultiViewPager pager = (MultiViewPager) findViewById(R.id.pager);
final FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
return 20;
}
@Override
public Fragment getItem(int position) {
return PageFragment.create(position);
}
};
pager.setAdapter(adapter);
}
示例13: addTabs
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
public void addTabs(FragmentStatePagerAdapter pageAdapter, final ViewPager pager, boolean scrollable) {
if (tab_showed) {
return;
}
final AppBarLayout appBar = (AppBarLayout) findViewById(R.id.appbar);
final TabLayout tabLayout = (TabLayout) getLayoutInflater().inflate(R.layout.tab_layout, null);
tabLayout.post(new Runnable() {
@Override
public void run() {
tabLayout.setupWithViewPager(pager);
}
});
if (!scrollable) {
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
appBar.addView(tabLayout, 1);
pager.setAdapter(pageAdapter);
tab_showed = true;
}
示例14: test1
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void test1() {
setContentView(R.layout.activity_test_2);
BackgroundViewPager2 viewPager = (BackgroundViewPager2) findViewById(R.id.viewPager2);
viewPager.setViewPagerBackground(R.drawable.wide_bg);
viewPager.setAdapter(new FragmentStatePagerAdapter(
getSupportFragmentManager()) {
@Override
public int getCount() {
return 3;
}
@Override
public Fragment getItem(int arg0) {
return MyFragment.newInstance(arg0 + 1);
}
});
}
示例15: test2
import android.support.v4.app.FragmentStatePagerAdapter; //导入依赖的package包/类
private void test2() {
setContentView(R.layout.activity_test);
BackgroundViewPager viewPager = (BackgroundViewPager) findViewById(R.id.flowViewPager1);
viewPager.setAdapter(new FragmentStatePagerAdapter(
getSupportFragmentManager()) {
@Override
public int getCount() {
return 3;
}
@Override
public Fragment getItem(int arg0) {
return MyFragment.newInstance(arg0 + 1);
}
});
}