title: Android FragmentPagerAdapter can't change tag of fragment
body: <p>I am developing a simple web beowser with dynamic tabs to allow user to add/remove them. I use <code>FragmentPagerAdapter</code>, <code>ViewPager</code> and <code>TabLayout</code> to do this. If I create 2 tabs (add 2 fragments to list) and then remove the second one, everything work well and I can add another fragment to list. But if I add 2 and then remove the firs one and try to add new fragment to list, I recieve exception:</p>
  
  <pre><code>java.lang.IllegalStateException: Can't change tag of fragment Page{162e3786 #1 id=0x7f0d007d android:switcher:2131558525:1}: was android:switcher:2131558525:1 now android:switcher:2131558525:0
  </code></pre>
  
  <p>I think thats because each fragment has unique id inside <code>FragmentPagerAdapter</code>. 2 fragments will have id's 0 and 1. If I remove the first item(id is 0) and then add new one(id will be 1). But item with id 1 is already exists! Is there a way to change id's programmatically or set id's when creating fragments? Thanks in advance!</p>
  
  <p>My <code>FragmentPagerAdapter</code>:</p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter {
  
      private List&lt;Page&gt; fragments;
  
      public PagerAdapter(FragmentManager fm, List&lt;Page&gt; pages) {
          super(fm);
          this.fragments = pages;
      }
  
      @Override
      public Fragment getItem(int position) {
          return this.fragments.get(position);
      }
  
      @Override
      public int getCount() {
          return this.fragments.size();
      }
  
      @Override
      public int getItemPosition(Object object) {
          int index = pages.indexOf(object);
          if (index == -1){
              return PagerAdapter.POSITION_NONE;
          } else {
              return index;
          }
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          FragmentManager manager = ((Fragment) object).getFragmentManager();
          FragmentTransaction trans = manager.beginTransaction();
          trans.remove((Fragment) object);
          trans.commit();
      }
  }
  </code></pre>