Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentManager;
- ...
- public class ScreenSlidePagerActivity extends FragmentActivity {
- /**
- * The number of pages (wizard steps) to show in this demo.
- */
- private static final int NUM_PAGES = 5;
- /**
- * The pager widget, which handles animation and allows swiping horizontally to access previous
- * and next wizard steps.
- */
- private ViewPager mPager;
- /**
- * The pager adapter, which provides the pages to the view pager widget.
- */
- private PagerAdapter mPagerAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_screen_slide);
- // Instantiate a ViewPager and a PagerAdapter.
- mPager = (ViewPager) findViewById(R.id.pager);
- mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
- mPager.setAdapter(mPagerAdapter);
- }
- @Override
- public void onBackPressed() {
- if (mPager.getCurrentItem() == 0) {
- // If the user is currently looking at the first step, allow the system to handle the
- // Back button. This calls finish() on this activity and pops the back stack.
- super.onBackPressed();
- } else {
- // Otherwise, select the previous step.
- mPager.setCurrentItem(mPager.getCurrentItem() - 1);
- }
- }
- /**
- * A simple pager adapter that represents 5 ScreenSlidePageFragment objects, in
- * sequence.
- */
- private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
- public ScreenSlidePagerAdapter(FragmentManager fm) {
- super(fm);
- }
- @Override
- public Fragment getItem(int position) {
- return new ScreenSlidePageFragment();
- }
- @Override
- public int getCount() {
- return NUM_PAGES;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement