title: Why it is not possible to use ViewPager within a Fragment? It actually is
body: <p>There are information that it is impossible to use <code>ViewPager</code> within a <code>Fragment</code> in many sources like &quot;<a href="http://commonsware.com" rel="noreferrer">The Busy Coders Guide for Android Developers</a>&quot; by Mark Murphy, or posts like <a href="https://stackoverflow.com/questions/7700226/display-fragment-viewpager-within-a-fragment/">this</a> on SO. I'm confused because I don't have such a problem and I successfully use <code>ViewPager</code> within my <code>Fragment</code>. The only distinction is that I instantiate a <code>ViewPager</code> not in <code>onCreateView()</code> method but in <code>onActivityCreated()</code>. And everything works perfectly fine.</p>
  <p>So the question is - may be I just don't know something and this is not recommended for some reason to make UI instantiations in <code>onActivityCreated()</code>? But again - everything works just fine.</p>
  <p>Here is the listing of the class and xml:</p>
  <h3>Class:</h3>
  <pre><code>public class ViewPagerFragment extends Fragment {
  
      static final int NUM_ITEMS = 2;
  
      private ViewPagerAdapter mAdapter;
      private ViewPager mPager;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          return inflater.inflate(R.layout.view_pager_fragment, container, false);
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
          mAdapter = new ViewPagerAdapter(getFragmentManager());
  
          mPager = (ViewPager) getView().findViewById(R.id.pager);
          mPager.setAdapter(mAdapter);
      }
  
      public static class ViewPagerAdapter extends FragmentPagerAdapter {
          public ViewPagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public Fragment getItem(int num) {
              if (num == 0) {
                  return new ItemsListFragment();
              } else {
                  return new FavsListFragment();
              }
          }
  
          @Override
          public int getCount() {
              return NUM_ITEMS;
          }
      }
  }
  </code></pre>
  <h3>Layout:</h3>
  <pre><code>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
                android:layout_width=&quot;fill_parent&quot;
                android:layout_height=&quot;fill_parent&quot;
                android:orientation=&quot;vertical&quot;&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id=&quot;@+id/pager&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;0dp&quot;
          android:layout_weight=&quot;1&quot;/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>