title: onCreateView is not always called after viewPagerAdapter.addTab()
body: <p>I want to create app with dynamic add/remove tabs option and I've got problem with one thing. </p>
  
  <p>When I'm adding tabs first time everything is ok but when I remove one tab and I want to add new tab again then there is no onCreateView called on that new fragment.</p>
  
  <p>Example:</p>
  
  <p>I add new 3 tabs:</p>
  
  <ul>
  <li>Add tab 1:</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>ViewPagerAdapter vpa = (ViewPagerAdapter) mViewPager.getAdapter();
  vpa.addTab("TAB 1");
  vpa.notifyDataSetChanged();
  </code></pre>
  
  
  
  <p><em>onCreateView is called.</em></p>
  
  <pre><code>some logs:
      [add tab] mViewPager.getChildCount() = 1
      [add tab] vpa.getCount() = 1
  </code></pre>
  
  <ul>
  <li>Add tab 2:</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>vpa.addTab("TAB 2");
  vpa.notifyDataSetChanged();
  </code></pre>
  
  
  
  <p><em>onCreateView is called.</em></p>
  
  <pre><code>some logs:
      [add tab] mViewPager.getChildCount() = 2
      [add tab] vpa.getCount() = 2
  </code></pre>
  
  <ul>
  <li>Add tab 3:</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>vpa.addTab("TAB 3");
  vpa.notifyDataSetChanged();
  </code></pre>
  
  
  
  <p><em>onCreateView is called.</em></p>
  
  <pre><code>some logs:
      [add tab] mViewPager.getChildCount() = 3
      [add tab] vpa.getCount() = 3
  </code></pre>
  
  <ul>
  <li>now I want to delete Tab 2:</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>vpa.removeTab("TAB 2");
  vpa.notifyDataSetChanged();
  </code></pre>
  
  
  
  <pre><code>some logs:
      [add tab] mViewPager.getChildCount() = 2
      [add tab] vpa.getCount() = 2
  </code></pre>
  
  <ul>
  <li>and I want to add Tab 2 again:</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>vpa.addTab("TAB 2");
  vpa.notifyDataSetChanged();
  </code></pre>
  
  
  
  <p><em>and there is no onCreateView called :(</em></p>
  
  <pre><code>some logs:
      [add tab] mViewPager.getChildCount() = 2
      [add tab] vpa.getCount() = 3
  </code></pre>
  
  <p>Can anyone know how to fix that? Why onCreateView is not always called?</p>
  
  <p><strong>App code:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>private void initViewpagerAndTabs(){
      mViewPager = (ViewPager) findViewById(R.id.viewpager_slave);
      mViewPager.setOffscreenPageLimit(10);
      mAdapterViewPager = new ViewPagerAdapter(getSupportFragmentManager());
      mViewPager.setAdapter(mAdapterViewPager);
      mTabLayout = (TabLayout) findViewById(R.id.tabLayout_slave);
      mTabLayout.setupWithViewPager(mViewPager);
  }
  </code></pre>
  
  
  
  <pre class="lang-java prettyprint-override"><code>/** Tabs content fragment */
  public static class DummyFragment extends Fragment implements RecyclerAdapter.ViewHolder.ClickListener {
      private RecyclerView mRecyclerView;
      private RecyclerAdapter mAdapterRecycler;
      private RecyclerView.LayoutManager mLayoutManager;
      private Fab fab;
  
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.content_slave, container, false);
  
          //setRetainInstance(true);
          initRecyclerView(view);
          fab = (Fab) getActivity().findViewById(R.id.fabRemoveItems);
  
          return view;
      }
  
      private void initRecyclerView(View view){
          mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_slave);
  
          // use this setting to improve performance if you know that changes
          // in content do not change the layout size of the RecyclerView
          mRecyclerView.setHasFixedSize(true);
  
          mLayoutManager = new LinearLayoutManager(getContext());
          mRecyclerView.setLayoutManager(mLayoutManager);
          RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
          itemAnimator.setAddDuration(500);
          itemAnimator.setRemoveDuration(500);
  
          mAdapterRecycler = new RecyclerAdapter(this);
          mRecyclerView.setAdapter(mAdapterRecycler);
      }
  
  }
  </code></pre>
  
  
  
  <pre class="lang-java prettyprint-override"><code>private class ViewPagerAdapter extends FragmentStatePagerAdapter {
      private final List&lt;DummyFragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
      public ViewPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      public DummyFragment getItem(int num) throws IndexOutOfBoundsException{
          return mFragmentList.get(num);
      }
  
      public void addTab(String title) throws Exception {
          if(isTabExist(title)){
              throw new Exception("Tabs already exist!");
          }
          //Log.d(TAG, "[addTab] mFragmentTitleList before add: " + mFragmentTitleList);
          //Log.d(TAG, "[addTab] mFragmentList before add: " + mFragmentList);
          mFragmentList.add(new DummyFragment());
          mFragmentTitleList.add(title);
          //Log.d(TAG, "[addTab] mFragmentTitleList after add: " + mFragmentTitleList);
          //Log.d(TAG, "[addTab] mFragmentList after add: " + mFragmentList);
      }
  
      public void removeTab(int position){
          //Log.d(TAG, "[removeTab] mFragmentTitleList before removed: " + mFragmentTitleList);
          //Log.d(TAG, "[removeTab] mFragmentList before removed: " + mFragmentList);
          mFragmentTitleList.remove(position);
          mFragmentList.remove(position);
          //Log.d(TAG, "[removeTab] mFragmentTitleList after removed: " + mFragmentTitleList);
          //Log.d(TAG, "[removeTab] mFragmentList after removed: " + mFragmentList);
      }
  
      private boolean isTabExist(String name){
          for(int i = 0; i &lt; mFragmentTitleList.size(); i++) {
              if (mFragmentTitleList.get(i).equals(name)) {
                  return true;
              }
          }
          return false;
      }
  
      public int getTabPosition(String tabName) throws IndexOutOfBoundsException{
          for(int i = 0; i &lt; mFragmentTitleList.size(); i++) {
              if (mFragmentTitleList.get(i).equals(tabName)) {
                  return i;
              }
          }
          throw new IndexOutOfBoundsException();
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          super.destroyItem(container, position, object);
        getSupportFragmentManager().beginTransaction().remove((Fragment) object)
                  .commit();
      }
  
      @Override
      public int getItemPosition(Object object) {
          if (mFragmentList.contains(object)) return mFragmentList.indexOf(object);
          else return POSITION_NONE;
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  }
  </code></pre>