title: Change the next page dynamically of a ViewPager
body: <p>I'm using a <code>ViewPager</code> and displaying a lot of different <code>Fragments</code> inside it, not only in content but they use different classes as well. The list to be displayed should be changed dynamically and even though I manage to swap items around and add new ones to the adapter(and calling <code>notifyDataSetChanged</code>), if I try changing the next item it will still slide to it when using <code>mPager.setCurrentItem(mPager.getCurrentItem() + 1);</code></p>
  
  <p>I am just adding a new <code>Fragment</code> between the current item and the current next one, it is displayed correctly in the adapter but as the next one was already preloaded then <code>getItem</code> in the adapter is not even called.</p>
  
  <p>Is there another method "stronger" than <code>notifyDataSetChanged</code> that tells my <code>ViewPager</code> that it should get the next item again?</p>
  
  <hr>
  
  <p>CODE SAMPLES:</p>
  
  <p>The add and get item methods inside my <code>FragmentPagerAdapter</code>(only samples, not the actual code)</p>
  
  <pre><code>public void add(@NonNull Integer fragmentIndex) {
      mFragmentOrder.add(fragmentIndex);
      notifyDataSetChanged();
  }
  
  @Override
  public Fragment getItem(int position) {
      int selectedFragment = mFragmentOrder(position);
      Fragment fragment;
  
      switch (selectedFragment) {
          case 1:
              fragment = new FragmentA();
              break;
          case 2:
              fragment = new FragmentB();
              break;
          case 3:
              fragment = new FragmentC();
              break;
          default:
              fragment = new FragmentD();
              break;
      }
  
      return fragment;
  }
  </code></pre>
  
  <p>This is the function used to go to the next item(I don't allow swiping)</p>
  
  <pre><code>public void goToNext() {
      mPager.setCurrentItem(mPager.getCurrentItem() + 1);
  }
  </code></pre>
  
  <hr>
  
  <p>EDITS:</p>
  
  <p>Edit 1: I had already tried using a <code>FragmentStatePagerAdapter</code> instead and setting the <code>OffscreenPageLimit</code> to 0, but to no avail.</p>
  
  <p>Edit 2: [Solution] Using a <code>FragmentStatePagerAdapter</code> AND overwriting the <code>getItemPosition</code> function to return <code>POSITION_NONE</code> or the index in the appropriate cases solved the problem. For some reason even after implementing the right version of this function the normal <code>FragmentPagerAdapter</code> kept delivering the wrong <code>Fragment</code>.</p>