title: How to remove pages in Android ViewPager?
body: <p>I'm trying to add/remove dynamically <code>fragments</code> in a <code>ViewPager</code> following a button click, but if I <code>remove</code> the fragment (a form) by clicking on back button, and add the fragment again, the form has kept its data (EditText not empty).</p>
  
  <p>Here is my adapter :</p>
  
  <pre><code>package com.thomas.playlists.viewPager;
  
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  
  import java.util.ArrayList;
  
  public class ViewPagerAdapter extends FragmentPagerAdapter
  {
      ArrayList&lt;Fragment&gt; mList = null;
  
      public ViewPagerAdapter(FragmentManager fm)
      {
          super(fm);
          mList = new ArrayList&lt;Fragment&gt;();
      }
  
      public void add(Fragment fragment)
      {
          mList.add(fragment);
      }
  
      public void removeLast()
      {
          if(mList.size() &gt; 1)
              mList.remove(getCount() - 1);
      }
  
      @Override
      public Fragment getItem(int i)
      {
          return mList.get(i);
      }
  
      @Override
      public int getCount()
      {
          return mList.size();
      }
  }
  </code></pre>
  
  <p>Adding proccess used twice (in main Activity) :</p>
  
  <pre><code>PlaylistFragment playlistFragment = new PlaylistFragment();
  
  mViewPagerAdapter.add(playlistFragment);
  mViewPagerAdapter.notifyDataSetChanged();
  mViewPager.setCurrentItem(mViewPagerAdapter.getCount() - 1, true);
  </code></pre>
  
  <p>Removing a page (still in main Activity) :</p>
  
  <pre><code>mViewPagerAdapter.removeLast();
  mViewPagerAdapter.notifyDataSetChanged();
  mViewPager.setCurrentItem(mViewPagerAdapter.getCount() - 1, true);
  </code></pre>
  
  <p>How can I remove the fragment properly ?</p>
  
  <p><strong>EDIT :</strong> I tried <a href="https://stackoverflow.com/questions/10396321/remove-fragment-page-from-viewpager-in-android#answer-10399127">this</a> but the form isn't reseted;</p>
  
  <p><strong>EDIT 2 :</strong> After instanciating the second fragment, its <code>onCreate()</code> method isn't called.</p>