title: It is possible to add/remove tabs in ViewPager at run time?
body: <pre><code>public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      Log.v(TAG, "onCreateView");
  
      View rootView = inflater.inflate(R.layout.fragment_home, container, false);
  
      // setting up the view pager and tab layout
      mViewPager = (ViewPager) rootView.findViewById(R.id.view_pager);
      mTabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout);
      PageAdapter adapter = new PageAdapter(getFragmentManager());
      mViewPager.setAdapter(adapter);
  
      mTabLayout.setupWithViewPager(mViewPager);
      mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
  
      return rootView;
  }
  </code></pre>
  
  <p>My custom pager adapter looks like this:</p>
  
  <pre><code>public class PageAdapter extends FragmentStatePagerAdapter {
  
      public PageAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          return new GroupTabFragment(position);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          String title = "";
          switch (position) {
              case 0:
                  title = "Game";    // this is from a template, i have to
                  break;             // return title dynamically
              case 1:
                  title = "Movie";
                  break;
          }
          return title;
      }
  
      @Override
      public int getCount() {
          return 2;                  // the tabs number is a subject of change
      }                              // i don't know it from the begining
  }
  </code></pre>
  
  <p>The problem i have is that i have to add or remove a tab when a button is clicked, or something like this.</p>
  
  <p>Each tab will display a classic list of objects.
  Thank you.</p>