title: Hide tab in FragmentPagerAdapter
body: <p>I need to hide the second tab on particular condition, I have tried in following way, Tab hided, and text also changed, but fragment didn't changed, I mean, If I hided the second tab then I am getting <code>FragmentStep2</code>[second tab's content] on third tab, </p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter {
  
      private static final String TAG = "PagerAdapter";
      private final String[] TITLES_WITH_STEP2 = {"step1", "step2", "step3", "step4"};
      private final String[] TITLES_WITHOUT_STEP2 = {"step1", "step3", "step4"};
      private ArrayList&lt;Fragment&gt; fragmentsList;
  
      private boolean isShowStep2Tab = true;
  
      public PagerAdapter(FragmentManager fm) {
          super(fm);
          fragmentsList = new ArrayList&lt;&gt;();
          fragmentsList.add(new FragmentStep1());
          fragmentsList.add(new FragmentStep2());
          fragmentsList.add(new FragmentStep3());
          fragmentsList.add(new FragmentStep4());
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          Log.v(TAG, "getPageTitle isShowStep2Tab : " + isShowStep2Tab);
          fragmentsList = new ArrayList&lt;&gt;();
          return isShowStep2Tab ? TITLES_WITH_STEP2[position] : TITLES_WITHOUT_STEP2[position];
      }
  
      @Override
      public Fragment getItem(int position) {
          /*Log.v(TAG, "getItem isShowStep2Tab : " + isShowStep2Tab);
          if (getPageTitle(position).equals("Step1")) {
              return new FragmentStep1();
          } else if (getPageTitle(position).equals("Step2")) {
              return new FragmentStep2();
          } else if (getPageTitle(position).equals("Step3")) {
              return new FragmentStep3();
          } else if (getPageTitle(position).equals("Step4")) {
              return new FragmentStep4();
          }else {
              return new FragmentStep4();
          }*/
          return fragmentsList.get(position);
      }
  
      @Override
      public int getCount() {
          Log.v(TAG, "getCount isShowStep2Tab : " + isShowStep2Tab);
          fragmentsList = new ArrayList&lt;&gt;();
          return isShowStep2Tab ? TITLES_WITH_STEP2.length : TITLES_WITHOUT_STEP2.length;
      }
  
      public void setShowFamilyTab(boolean isShowStep2Tab) {
          this.isShowStep2Tab = isShowStep2Tab;
          fragmentsList = new ArrayList&lt;&gt;();
          if (isShowStep2Tab) {
              fragmentsList.add(new FragmentStep1());
              fragmentsList.add(new FragmentStep2());
              fragmentsList.add(new FragmentStep3());
              fragmentsList.add(new FragmentStep4());
          } else {
              fragmentsList.add(new FragmentStep1());
              fragmentsList.add(new FragmentStep3());
              fragmentsList.add(new FragmentStep4());
          }
          notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>I don't know what is the problem here. </p>