title: listview in a viewpager based on fragments
body: <p>I'm using a viewpager based on fragments, and it works amazingly. My viewpager shows a button on each page (since it's what I put in the layout xml file of each fragment).
  Now I want to have a listview with different data on each page instead of the buttons. And that's why in the first place I opted to use fragments. 
  The problem is that I didn't find a way to integrate listviews in my viewpager.
  Any ideas please?</p>
  
  <p>Here is my code :</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>    public class MainActivity extends FragmentActivity{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          List&lt;Fragment&gt; fragments = new Vector&lt;Fragment&gt;();
          fragments.add(Fragment.instantiate(this, FragmentA.class.getName()));
          fragments.add(Fragment.instantiate(this, FragmentB.class.getName()));
          fragments.add(Fragment.instantiate(this, FragmentC.class.getName()));
          ViewPagerAdapter adapter = new ViewPagerAdapter(super.getSupportFragmentManager(), fragments);
          ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
          pager.setAdapter(adapter);
          pager.setOffscreenPageLimit(2);
          pager.setCurrentItem(1);
      }
  }
  </code></pre>
  
  <p>main.xml declaring the viewpager</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.view.ViewPager
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/viewpager"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" &gt;
  
      &lt;android.support.v4.view.PagerTabStrip
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="top" /&gt;
  &lt;/android.support.v4.view.ViewPager&gt;
  </code></pre>
  
  <p>ViewPagerAdapter.java</p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter {
  
      private List&lt;Fragment&gt; fragments;
      private static String[] titles = new String[] {"A", "B", "C"};
  
      public ViewPagerAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments) {
          super(fm);
          this.fragments = fragments;
      }
  
      @Override
      public Fragment getItem(int position) {
          return this.fragments.get(position);
      }
  
      @Override
      public int getCount() {
          return this.fragments.size();
      }
  
      @Override
      public String getPageTitle( int position )
      {
          return titles[ position ];
      }
  }
  </code></pre>
  
  <p>FragmentA.java</p>
  
  <pre><code>    public class FragmentA extends Fragment {
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_a, container, false);
      }
  }
  </code></pre>
  
  <p>fragment_a.xml only contains a button</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;Button android:text="@string/a"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>