title: How to load the fragments when the tab is selected or page is swiped
body: <p>when I am swiping tabs are changing but fragment that I attached is not loading.
  I have created 4 fragments and their layouts
  I have included pagerAdapter in the mainActivity class 
  <a href="http://i.stack.imgur.com/FShbS.png" rel="nofollow">output(showing blank page when tab is selected)</a>
  Here is my MainActivity.java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  private TabLayout tabLayout;
  private ViewPager viewPager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setDisplayShowHomeEnabled(true);
  
      tabLayout = (TabLayout) findViewById(R.id.tab_layout);
      viewPager = (ViewPager) findViewById(R.id.viewpager);
      setupViewPager(viewPager);
      tabLayout.setupWithViewPager(viewPager);
      tabLayout.setOnTabSelectedListener(onTabSelectedListener(viewPager));
  
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      adapter.addFragment(new FragmentOne(), "Home");
      adapter.addFragment(new FragmentTwo(), "e-Profile");
      adapter.addFragment(new FragmentThree(), "Results");
      adapter.addFragment(new FragmentFour(), "Outpass");
      viewPager.setAdapter(adapter);
      viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
      onTabSelectedListener(viewPager);
  }
  
  private TabLayout.OnTabSelectedListener onTabSelectedListener(final ViewPager pager) {
      return new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
              pager.setCurrentItem(tab.getPosition());
          }
  
          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
  
          }
  
          @Override
          public void onTabReselected(TabLayout.Tab tab) {
  
          }
      };
  }
  }
  </code></pre>
  
  <p>this is my viewpagerAdapter. </p>
  
  <pre><code>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>MyFragment</p>
  
  <pre><code>public class FragmentOne extends Fragment{
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      return inflater.inflate(R.layout.fragment_one, container, false);
  }
  
  }
  </code></pre>