title: How can I remove a fragment and tab from ViewPager and Tablayout?
body: <p>I have search a lot about this solution. I tried remove from <em>mFragmentList</em> and <em>mFragmentTitleList</em> directly. And I also tried call the <em>destroyItem</em>. Many methods have been tried. None of them worked. I have been stuck on this problem for few days. Is there Any answer could help? Thanks.</p>
  
  <pre><code>public final  class OrdersViewPagerAdapter extends android.support.v4.app.FragmentPagerAdapter{
  private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
  private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
  public OrdersViewPagerAdapter(FragmentManager manager) {
      super(manager);
  }
  
  @Override
  public Fragment getItem(int position) {
      return mFragmentList.get(position);
  }
  
  @Override
  public int getCount() {
      return mFragmentList.size();
  }
  
  public void addFragment(Fragment fragment, String title) {
      mFragmentList.add(fragment);
      mFragmentTitleList.add(title);
  }
  
  
  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
      super.destroyItem(container, position, object);
      if (position &lt;= getCount()) {
          FragmentManager manager = ((Fragment) object).getFragmentManager();
          FragmentTransaction trans = manager.beginTransaction();
          trans.remove((Fragment) object);
          trans.commit();
      }
  }
  
  @Override
  public CharSequence getPageTitle(int position) {
      return mFragmentTitleList.get(position);
  }
  
  public void removeView(String  title, ViewGroup view, TabLayout tabLayout) {
      int index=-1;
  
      int count=mFragmentTitleList.size();
  
      for (int i=0;i&lt;count;i++){
          String mtitle=mFragmentTitleList.get(i);
          if (mtitle.equals(title)){
              index=i;
              break;
          }
      }
      if (index!=-1) {
          mFragmentTitleList.remove(index);
          tabLayout.removeTabAt(index);
          destroyItem(view,index,mFragmentList.get(index));
  
  
  
          notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>}</p>