title: Fragment onCreateView method not called in TabLayout with ViewPagerAdapter
body: <p>I have follow this link to implement tablayout <a href="http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/" rel="nofollow noreferrer">Android Material Design working with Tabs</a></p>
  
  <p>Now what I did I use fragment instead of Activity for tablayout.</p>
  
  <p>Below is code :-</p>
  
  <pre><code>public class HopitalTabLayoutFragment extends Fragment {
  
  private TabLayout tabLayout;
  private ViewPager viewPager;
  
  public HopitalTabLayoutFragment() {
  
  }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.fragment_hopital_tab_layout, container, false);
  
      viewPager = (ViewPager)view. findViewById(R.id.viewpager);
      setupViewPager(viewPager);
  
      tabLayout = (TabLayout)view. findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(viewPager);
  
      return view;
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getFragmentManager());
  
      adapter.addFragment(new OneFragment(), "ONE");
      adapter.addFragment(new TwoFragment(), "TWO");
      adapter.addFragment(new ThreeFragment(), "THREE");
  
      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 addFragment(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
  
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  }
  }
  </code></pre>
  
  <p>and add this fragment from Activity :-</p>
  
  <pre><code>public class HomeActivityDrawer extends AppCompatActivity {
  
  private Toolbar toolbar;
  private NavigationView navigation_view_left, navigation_view_right;
  private DrawerLayout drawerLayout;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_home_drawer);
  
  
  drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
  drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
  header = (RelativeLayout) findViewById(R.id.header);
  
  toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  
  fragment = new HopitalTabLayoutFragment();
  }
  }
  </code></pre>
  
  <p>These are my three fragments which are used in tab layout:-</p>
  
  <pre><code>public class TwoFragment extends Fragment {
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.fragment_two, container, false);
  
      TextView tv = (TextView) view.findViewById(R.id.tv);
      tv.setText("DONE");
         return view;
  }
  }
  </code></pre>
  
  <p>Similarly One and Three.</p>
  
  <p>Now the problem is that at first time all the three fragments are loaded and <code>onCreateView</code> method runs but when I open <code>tablayout</code> again only fragment One initiate not the second one. What's going wrong in this code? Please help!!</p>