title: How can I add Tabs & Fragment dynamically
body: <p>How can I add Tabs &amp; Fragment dynamically ?</p>
  
  <p>My code :</p>
  
  <pre><code>    private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      for (int i = 0; i &lt; 4; i++) {
      adapter.addFrag(new TabFragment(), "Tab"+i);
       }
      viewPager.setAdapter(adapter);
       }
  
  class ViewPagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
      public ViewPagerAdapter(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      public void addFrag(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  }
  </code></pre>
  
  <p>Tab Fragment</p>
  
  <pre><code>public class TabFragment extends ListFragment {
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.activty_listview,container, false);
      listView = (ListView) rootView.findViewById(android.R.id.list);
      return rootView;
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Suppose my tab names are "Tab1, Tab2, Tab3" 
  How can I add tabs dynamically according to the Array if I get above and how to tab fragment know which tab selected.</p>
  
  <p>Any suggestions are welcomed.</p>
  
  <p>Thanks in advance:)</p>