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


Java FragmentStatePagerAdapter类代码示例

本文整理汇总了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);
}
 
开发者ID:brarcher,项目名称:budget-watch,代码行数:19,代码来源:TransactionActivityTest.java

示例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;
}
 
开发者ID:fashare2015,项目名称:MVVM-JueJin,代码行数:20,代码来源:LoopPagerAdapterWrapper.java

示例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);
}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:21,代码来源:PlaylistFragment.java

示例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);
}
 
开发者ID:yangjiantao,项目名称:AndroidUiKit,代码行数:26,代码来源:PhotoViewerActivity.java

示例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);
}
 
开发者ID:yangchong211,项目名称:YCUtils,代码行数:24,代码来源:BackHandlerHelper.java

示例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);
}
 
开发者ID:ikidou,项目名称:FragmentBackHandler,代码行数:27,代码来源:BackHandlerHelper.java

示例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"));
}
 
开发者ID:brarcher,项目名称:budget-watch,代码行数:17,代码来源:TransactionActivityTest.java

示例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;
			}
		}
	};
	
}
 
开发者ID:androidWeq,项目名称:ItHome,代码行数:24,代码来源:Index.java

示例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;

            }
        }


    }
 
开发者ID:dhelleberg,项目名称:pegel-online-android,代码行数:27,代码来源:PegelDataActivity.java

示例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;
}
 
开发者ID:citruspay,项目名称:citrus-android-sdk,代码行数:24,代码来源:CardPaymentFragment.java

示例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);
}
 
开发者ID:xiaozhi003,项目名称:BeautyGallery,代码行数:19,代码来源:BeautyPagerActivity.java

示例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);
}
 
开发者ID:Pixplicity,项目名称:MultiViewPager,代码行数:23,代码来源:PagerActivity.java

示例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;
}
 
开发者ID:pennlabs,项目名称:penn-mobile-android,代码行数:22,代码来源:MainActivity.java

示例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);
		}
	});
}
 
开发者ID:MoshDev,项目名称:BackgroundViewPager,代码行数:20,代码来源:TestActivity.java

示例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);
		}
	});
}
 
开发者ID:MoshDev,项目名称:BackgroundViewPager,代码行数:19,代码来源:TestActivity.java


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