title: Android Viewpager how to dynamically remove a Fragment?
body: <p>I have been struggling a few days with building functionality in my application that allows a user to remove a page/Fragment from a Viewpager, I have tried changing my FragmentPageAdapter to a FragmentStatePageAdapter and override my  <code>getItemPosition()</code> to  <code>return POSITION_NONE;</code> however this still does not allow me to remove the Fragment dynamically when I call <code>fragments.remove(page);</code></p>
  
  <pre><code>pageAdapter.notifyDataSetChanged();
  </code></pre>
  
  <p>has anyone done this successfully before? seems like it should be really simple but it hasnt been, below is my fragment adapter, any help would go a long way thanks! </p>
  
  <pre><code>class MyPageAdapter extends FragmentStatePagerAdapter {
  
      private List&lt;Fragment&gt; fragments;
  
      public MyPageAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments) {
  
          super(fm);
  
          this.fragments = fragments;
  
      }
  
      @Override
      public int getItemPosition(Object object) {
          return POSITION_NONE;
      }
  
      @Override
      public Fragment getItem(int position) {
  
          return this.fragments.get(position);
  
      }
  
      @Override
      public float getPageWidth(int position) {
  
          if (position == 0) {
              return (0.75f);
          } else {
              return (1f);
          }
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
  
          MyFragment theFragment = (MyFragment) this.fragments.get(position);
  
          return theFragment.returnTitle();
  
      }
  
      @Override
      public int getCount() {
  
          return this.fragments.size();
  
      }
  
  }
  </code></pre>