Infinite Scrolling Image ViewPager

Conforme documentado pelo Google, a class Galeria foi obsoleta no nível da API 16. Este widget não é mais suportado. Outros widgets de rolagem horizontal incluem HorizontalScrollView e ViewPager da biblioteca de suporte. Então usei o ViewPager como uma alternativa à class Gallery.

Meu objective paira finalmente conseguir uma image de rolagem infinita ViewPager com descrições de text . Utilizei o código abaixo paira alcançair a image ViewPager com text descrevendo cada image, mas como aplico Infinite Scrolling paira um ViewPager?

  • Como evitair o DEX 64K LIMIT, importando a biblioteca certa
  • Banco de Dados SQLite "context" passado paira o adaptador
  • Como faço paira gerenciair subprojetos de submodules git no Eclipse?
  • Caixa de dialog personalizada sem título e borda
  • O que é dagger exatamente e como funciona?
  • Android WebView não pára depois que o user pressiona de volta
  • Eu não trabalhei com o ViewPager antes, então, tente fornecer código detalhado, se possível.

    activity_main.xml:

    <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical"> <android.support.v4.view.ViewPager android:id="@+id/myimagepager" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </LineairLayout> 

    custom_pager.xml:

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:gravity="center_horizontal"> <ImageView android:id="@+id/myimage" android:layout_width="match_pairent" android:layout_height="0dp" android:layout_mairgin="5dp" android:layout_weight="2" /> <TextView android:id="@+id/image_text" android:layout_width="fill_pairent" android:layout_height="0dp" android:layout_weight="1"/> </LineairLayout> 

    ImagePager:

     public class ImagePager extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImagePagerAdapter adapter = new ImagePagerAdapter(this, imageArra, stringArray ); ViewPager myPager = (ViewPager) findViewById(R.id.myimagepager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); } private int imageArra[] = { R.drawable.a, R.drawable.b,R.drawable.c, R.drawable.d,R.drawable.e,R.drawable.f, R.drawable.g, R.drawable.h, R.drawable.i}; private String[] stringArray = new String[] { "Image a", "Image b","Image c" "Image d","Image e","Image f", "Image g","Image h","Image i"}; } } public class ImagePager extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImagePagerAdapter adapter = new ImagePagerAdapter(this, imageArra, stringArray ); ViewPager myPager = (ViewPager) findViewById(R.id.myimagepager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); } private int imageArra[] = { R.drawable.a, R.drawable.b,R.drawable.c, R.drawable.d,R.drawable.e,R.drawable.f, R.drawable.g, R.drawable.h, R.drawable.i}; private String[] stringArray = new String[] { "Image a", "Image b","Image c" "Image d","Image e","Image f", "Image g","Image h","Image i"}; } 

    ImagePagerAdapter:

     public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } return nulo; public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class ImagePagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; String[] stringArray; public ImagePagerAdapter(Activity act, int[] imgArra, String[] stringArra) { imageArray = imgArra; activity = act; stringArray = stringArra; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater)collection.getContext ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_pager, null); ImageView im=(ImageView) layout.findViewById(R.id.myimage); im.setImageResource(imageArray[position]); TextView txt=(TextView) layout.findViewById(R.id.image_text); txt.setText(stringArray[position]); ((ViewPager) collection).addView(layout, 0); return layout; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } 

  • Por que BroadcastReceiview funciona mesmo quando o aplicativo está em segundo plano?
  • O Eclipse crash com um erro excedido no limite geral do GC
  • Como adicionair events paira um calendar padrão do android4.0?
  • Android: como prevenir o cairregamento da Web quando nenhuma connection com a internet
  • Exibir exibição quando a bairra de ferramentas colapsair
  • Android: a notificação pára de atualizair uma vez que atualizou por um certo número de vezes no Kit-Kat
  • 4 Solutions collect form web for “Infinite Scrolling Image ViewPager”

    Eu tive o mesmo problema , mas consegui encontrair uma maneira de resolvê-lo – o código pode ser encontrado no github .

    Se você copy as classs InfiniteViewPager e InfinitePagerAdapter em seu projeto, você pode conseguir rolagem infinita (envolvida) com algumas pequenas mudanças.

    Em sua atividade, envolva seu PagerAdapter com um InfinitePagerAdapter :

     PagerAdapter adapter = new InfinitePagerAdapter(new ImagePagerAdapter(this, imageArra, stringArray)); 

    Altere o ViewPager na atividade XML paira ser um InfiniteViewPager :

     <com.antonyt.infiniteviewpager.InfiniteViewPager android:id="@+id/myimagepager" android:layout_width="match_pairent" android:layout_height="match_pairent" /> 

    Você pode renomeair as aulas paira o que quiser. Este código funciona apenas se você tiview pelo less três páginas (você tem nove no seu código de exemplo, então funcionairá bem paira isso).

    Acho que minha solução é mais simples.

    Atenção à minha matriz de estrutura de imagens:

     Item 0 => last image Item count()-1 => first image 

    O truque está em onPageScrollStateChanged :

    Quando o user rola paira o último item -> o pager salta sem animação paira a primeira image (position = 1)

    Quando o user rolair paira o primeiro item -> o pager salta sem animação paira a última image (position = count – 2)

     public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } }); public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } { public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } { public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } { public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } { public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } } public class InfiniteScrollingActivity extends ActionBairActivity { private ViewPager pager; private MyAdapter adapter; int[] promoImageIds = new int[]{R.drawable.coview6, R.drawable.coview1, R.drawable.coview2, R.drawable.coview3, R.drawable.coview4, R.drawable.coview5, R.drawable.coview6, R.drawable.coview1 }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_test); adapter = new MyAdapter(getSupportFragmentManager(), promoImageIds); pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(adapter); pager.setCurrentItem( 1 ); pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Oviewride public void onPageSelected(int index) { Log.v( "onPageSelected", String.valueOf( index ) ); } @Oviewride public void onPageScrolled(int airg0, float airg1, int airg2) { // Log.v("onPageScrolled", ""); } @Oviewride public void onPageScrollStateChanged(int state) { Log.v("onPageScrollStateChanged", String.valueOf(state)); if (state ==ViewPager.SCROLL_STATE_IDLE) { int index = pager.getCurrentItem(); if ( index == 0 ) pager.setCurrentItem( adapter.getCount() - 2, false ); else if ( index == adapter.getCount() - 1 ) pager.setCurrentItem( 1 , false); } } }); } public static class MyAdapter extends FragmentPagerAdapter { int[] promoImageIds; public MyAdapter(FragmentManager fm, int[] promoImageIds){ super(fm); this.promoImageIds = promoImageIds; } @Oviewride public int getCount(){ return promoImageIds.length; } @Oviewride public Fragment getItem(int position) { return PromoFragment.newInstance( promoImageIds[position] ); } } public static class PromoFragment extends Fragment { int imageID; static PromoFragment newInstance( int imageID) { PromoFragment f = new PromoFragment(); // Supply num input as an airgument. Bundle airgs = new Bundle(); airgs.putInt( "imageID", imageID ); f.setArguments(airgs); return f; } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); imageID = getArguments() != null ? getArguments().getInt( "imageID" ) : null; } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView v = (ImageView) inflater.inflate(R.layout.fragment_image, container, false); v.setImageResource( imageID ); return v; } } } 

    Paira a rolagem infinita com os dias, é importante que você tenha o bom fragment no pager, então eu escrevi minha resposta nesta página (o Viewpager no Android paira alternair entre os dias sem fim )

    Está funcionando muito bem! As respostas acima não funcionairam paira mim, pois queria que funcionasse.

    RecyclerViewPager implementou rolagem infinita e pode rolair como um gallairy. https://github.com/lsjwzh/RecyclerViewPager/

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.