Back to project page InfiniteViewPager.
The source code is released under:
Copyright (c) 2012 Antony Tran Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...
If you think the Android project InfiniteViewPager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.antonyt.infiniteviewpager; /* www . j ava 2s . co m*/ import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class InfiniteViewPagerActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { int[] colours = new int[]{Color.CYAN, Color.GRAY, Color.MAGENTA, Color.LTGRAY, Color.GREEN, Color.WHITE, Color.YELLOW}; @Override public int getCount() { return colours.length; } @Override public Fragment getItem(int position) { Fragment fragment = new ColourFragment(); Bundle args = new Bundle(); args.putInt("colour", colours[position]); args.putInt("identifier", position); fragment.setArguments(args); return fragment; } }; // wrap pager to provide infinite paging with wrap-around PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter); // actually an InfiniteViewPager ViewPager viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(wrappedAdapter); } }