title: Android endless FragmentPagerAdapter using new adapter on swipe
body: <p>I am trying to create an endless <code>FragmentPagerAdapter</code> , on swipe to replace the adapter with a new one, and depending on which side you swipe, a global variable to increase or decrease, so you can know on what position you are. So I have tried this</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
      mViewPager = (ViewPager) findViewById(R.id.pager);
      mViewPager.setOffscreenPageLimit(0);
      mViewPager.setAdapter(mSectionsPagerAdapter);
      mViewPager.setCurrentItem(1);
      mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
  
          @Override
          public void onPageSelected(int arg0) {
          }
  
          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {
              if (mViewPager.getCurrentItem() == 0) {
                  // left
                  mViewPager.setAdapter(null);
                  mViewPager.setAdapter(new SectionsPagerAdapter(getSupportFragmentManager()));
                  mViewPager.setCurrentItem(1);
                  MyVar.INST.position--;
              } else if (mViewPager.getCurrentItem() == 2) {
                  // right
                  mViewPager.setAdapter(null);
                  mViewPager.setAdapter(new SectionsPagerAdapter(getSupportFragmentManager()));
                  mViewPager.setCurrentItem(1);
                  MyVar.INST.position++;
              }
          }
  
          @Override
          public void onPageScrollStateChanged(int arg0) {
          }
      });
  }
  </code></pre>
  
  <p>the problem is, even though I have set the offscreenPageLimit to 0, Android still caches the 3 fragment in the memory by default, so when I scroll to the right, the method inside OnPageChangeListener is not being called, therefore the global variable is not being incremented properly....
  Any idea how can I fix that?</p>
  
  <p>EDIT: Here is the adapter</p>
  
  <pre><code>private class SectionsPagerAdapter extends FragmentPagerAdapter {
  
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          return Fragment1.newInstance(MyVar.INST.position + position);
      }
  
      @Override
      public int getCount() {
          return 3;
      }
  
  }
  </code></pre>