title: Tabs + ViewPager + FragmentStatePagerAdapter - How to remove fragment?
body: <p>I'm using the "Tabs + Swipe" project and I'm having a difficult time removing a fragment.</p>
  
  <p><strong>Steps I'm doing:</strong></p>
  
  <ol>
  <li>Remove tab from database</li>
  <li>Remove tab from the FragmentStatePagerAdapter data source</li>
  <li>Remove tab from the actionBar.</li>
  <li>Remove fragment using Support FragmentManager.</li>
  </ol>
  
  <p><strong>The problem:</strong>
  After I perform the remove, for some reason, I can still scroll to the right and see an empty fragment. I can't select it, it just bounces back.
  It seems like the fragment is not being removed but rather changes its position to the tag from the left.</p>
  
  <p><strong>My Adapter:</strong></p>
  
  <pre><code>public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
  
          public SectionsPagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public Fragment getItem(int position) {
              Fragment fragment = new TabFragment();
  
              Bundle args = new Bundle();
              args.putInt(TabFragment.ARG_TAB_POSITION, position);
              fragment.setArguments(args);
  
              return fragment;
          }
  
          @Override
          public int getCount() {
              return tabsList.size();
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return tabsList.get(position).getTitle();
          }
  
          @Override
          public void destroyItem(ViewGroup container, int position, Object object) {
              super.destroyItem(container, position, object);
              FragmentManager manager = ((Fragment)object).getFragmentManager();
              android.support.v4.app.FragmentTransaction trans = manager.beginTransaction();
              trans.remove((Fragment)object);
              trans.commit();
          }
      }
  </code></pre>
  
  <p><strong>My remove method (called from within the fragment):</strong></p>
  
  <pre><code>public void removeTab() {
              mTabTableHandler.deleteTab(tab.getId()); //db
              tabsList.remove(tabPosition); //data source
              actionBar.removeTabAt(tabPosition); // actionbar
  
              getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit(); // support fragmentmanager
  
              tabsList = mTabTableHandler.query(); //requery db
              mSectionsPagerAdapter.notifyDataSetChanged(); //notify adapter
          }
  </code></pre>
  
  <p>Appreciate the help!</p>