title: Calling notifyDataSetChanged from instantiateItem()
body: <p>I have a requirement to show a ViewPager displaying initially just one View.
  Once this View goes through measure &amp; layout pass, depending on the result of these I might need to change the contents of the adapter.
  While doing so, I've come across a scenario where the ViewPager will not follow through with it's movement while trying to swipe to the next item from a certain position.<br>
  I'm sure I'm doing something wrong in my adapter implementation, yet I can't point my finger at the problem.</p>
  
  <p>For the sake of demonstration I've created a dummy adapter that will mimic what happens on my actual project.
  In order to reproduce the issue just try to swipe all the way to position 2 (3rd item), result is you can't get past position 1 (2nd item).</p>
  
  <p>Thanks!</p>
  
  <pre><code>public class CustomAdapter extends PagerAdapter {
      int pages = 0;
  
      @Override
      public int getCount() {
          return pages;
      }
  
      @Override
      public boolean isViewFromObject(View view, Object o) {
          return view == o;
      }
  
      public void setPages(int x) {
          this.pages = x;
      }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          TextView tv = new TextView(MainActivity.this);
          ViewGroup.LayoutParams lp =
                  new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                          ViewGroup.LayoutParams.WRAP_CONTENT);
  
          tv.setLayoutParams(lp);
          tv.setText("Position: " + position);
  
          if (position == 0 &amp;&amp; pages == 1) {
              setPages(2);
              notifyDataSetChanged();
          }
          if (position == 1 &amp;&amp; pages == 2) {
              setPages(3);
              notifyDataSetChanged();
          }
  
          container.addView(tv);
          return tv;
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          container.removeView((View) object);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Activity (onCreate or so):</p>
  
  <pre><code>    CustomAdapter adapter = new CustomAdapter();
      adapter.setPages(1);
      vp.setAdapter(adapter);
      adapter.notifyDataSetChanged();
  </code></pre>