title: Using viewPager with fragments android?
body: <p>I have already tried a lot of tutorials but i am kind of new on android, so here's my problem. I need a Viewpager inside a fragment of Navigation Drawer.
  <br><br>I have a drawer layout with the MainActivity and fragment A , B , C and D . 
  <br>On fragment C I have my layout , like textViews, imageViews and I need to add a viewPager like on iOS devices.
  The problem is every tutorial, and questions answered here, says to start the PageAdapter on the Activity , but I need to use it on the Fragment because it's where I have the information to populate the information of the C fragment.
  <br>The view pager that should appear, only contains a textView that is populated with a webservice request where I get the message to put on the textView, that's why i need this on the Fragment C.
  <br> So here is my pageAdapter:</p>
  
  <pre><code>public class PageAdapter extends FragmentPagerAdapter {
  private String message;
  
  public PageAdapter(FragmentManager fm , String message) {
      super(fm);
      this.message = message;
  
  }
  
  /**
   * Get fragment corresponding to a specific position. This will be used to populate the
   * contents of the view pager
   *
   * @param position Position to fetch fragment for.
   * @return Fragment for specified position.
   */
  @Override
  public Fragment getItem(int position) {
      // getItem is called to instantiate the fragment for the given page.
  
      Fragment fragment = new PageVestiarioFragment();
      Bundle args = new Bundle();
      args.putString("message", message);
      fragment.setArguments(args);
      return fragment;
  }
  
  /**
   * Get number of pages the should render.
   *
   * @return Number of fragments to be rendered as pages.
   */
  @Override
  public int getCount() {
      // Show 3 total pages.
      return 3;
  }
  }
  </code></pre>
  
  <p>And this is my pageViewer item : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center_horizontal"
  android:id="@+id/pageViewLayout"
  tools:context="com.example.mobirama.golaco.VestiarioFragment"&gt;
  
  &lt;TextView
      android:id="@+id/message_TextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Mensagem recebida via rest"
      android:textSize="20sp"
      android:textColor="@color/text_green" /&gt;
    &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And this is my fragment C layout, as long as there is too much information i'll put just the piece where there is the pageview (this is inside a relativeLayout)</p>
  
  <pre><code> &lt;HorizontalScrollView
              android:id="@+id/messages_ScrollView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerVertical="true"
              android:layout_centerHorizontal="true" &gt;
  
              &lt;RelativeLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:gravity="center_horizontal"&gt;
  
                  &lt;android.support.v4.view.ViewPager
                      android:id="@+id/pager"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content" /&gt;
  
               &lt;/RelativeLayout&gt;
  
           &lt;/HorizontalScrollView&gt;
  </code></pre>
  
  <p>Just a piece of where I set the information</p>
  
  <pre><code> for (Integer i = 0; i &lt; messages.length; i++) {
              if (messages[i] != null) {
                  items.add(messages[i]);
                  mAdapter = new PageAdapter(getChildFragmentManager() , messages[i].getMessage());
                  pager.setAdapter(mAdapter);
              }
          }
  </code></pre>
  
  <p>The problem is android studio shows this message : android.support.v4.app.fragmentmanager does not match with android.support.app.fragmentmanager</p>
  
  <p>I tried to change to support v13 but didn't work.</p>
  
  <p>Can someone help me?</p>