title: Remove a fragment of a specific index from a view pager
body: <p>Im trying to remove a fragment from a specific index. But that is really happening is the viewpager and pagerAdapter are just hiding the last fragment.</p>
  
  <p>This is the code:</p>
  
  <pre><code>public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
  
  ArrayList&lt;String&gt; data_fragment;
  
  public SectionsPagerAdapter(FragmentManager fm) {
      super(fm);
      data_fragment = new ArrayList&lt;&gt;();
      data_fragment.add(0, "Página 0");
  }
  
  public void addNewFragmentData(String data) {
      // int last_position = data_fragment.size();
      data_fragment.add(data);
      notifyDataSetChanged();
  }
  
  public void removeFragmentData(int index) {
      // destroyItem(container, position, object);
      data_fragment.remove(index);
      notifyDataSetChanged();
  }
  
  @Override
  public int getItemPosition(Object object) {
  
      return POSITION_NONE;
  }
  
  // @Override
  // public void destroyItem(ViewGroup container, int position, Object object)
  // {
  // data_fragment.remove(position);
  // super.destroyItem(container, position, object);
  // }
  
  @Override
  public Fragment getItem(int position) {
      Log.i("paginas", "getItem");
      return LienzoFragment.newInstance(position);
  }
  
  @Override
  public int getCount() {
      return data_fragment.size();
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
          return data_fragment.get(position);
      }
  }
  </code></pre>
  
  <p>As you see, I'm trying to avoid retain any fragment object. My approach is just keep the title and then each fragment manage its own save/restore state by itself.</p>
  
  <pre><code>int tab_selected = mViewPager.getCurrentItem();
  mSectionsPagerAdapter.removeFragmentData(tab_selected);
  //mSectionsPagerAdapter.destroyItem(mViewPager, tab_selected, mViewPager.getChildAt(tab_selected));
  mViewPager.removeViewAt(tab_selected);
  mViewPager.setCurrentItem(tab_selected-1, true);
  </code></pre>