title: Is my implementation of "infinite scrolling" in ViewPager efficient
body: <p>I am using a ViewPager with FragmentStatePagerAdapter to display images. I am able to successfully display images and now I am trying to implement "infinite scrolling". "Infinite scrolling" means that I am able to loop to the first image once I reach the last image &amp; and I am to loop to the last image from the first image. Below is an illustration of "infinite scrolling" for clarification. </p>
  
  <p>"infinite scrolling" : <strong>(... C &lt;-> A &lt;-> B &lt;-> C &lt;-> A ... )</strong></p>
  
  <p>My code implementation of this is below:</p>
  
  <pre><code>/* PagerAdapter class */
  public class SlidePagerAdapter extends FragmentStatePagerAdapter {
      private int urlPicArryIndex = 0;
  
      public SlidePagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public int getCount() {
          return NUM_ITEMS;
      }
  
      @Override
      public Fragment getItem(int position) {
  
          System.err.println("orignal position = " + position);
  
          position = position % urlPicArray.size();
          urlPicArryIndex = position;
  
          System.err.println("urlPicArryIndex = " + urlPicArryIndex);
          System.err.println("position = " + position + ",     NUM_ITEMS = " + NUM_ITEMS);
  
          return PictureSectionFragment.newInstance(position, urlPicArray.get(urlPicArryIndex));
      }
  }
  </code></pre>
  
  <p>Here are what variables are set to that is not displayed in the code snippet above:</p>
  
  <p><strong>NUM_ITEMS</strong> is set to 800 </p>
  
  <p><strong>urlPicArray</strong> is an arrayList of images set in another method.</p>
  
  <p>My code works for "infinite scrolling", however, I am concerned that this is not efficient. By setting <strong>NUM_ITEMS</strong> to 800 does this set aside this large amount of fragment space in memory? BTW I realize that this is not truly infinite scrolling, however, it should be sufficient for most real world use cases.</p>
  
  <p>I am a just getting into android dev so any help / guidance would be greatly appreciated!</p>