title: Making Activity with several ViewPagers
body: <p>Im trying to make an Activity that contains several View's added to LinearLayout inside ScrollView.Those View's are layout files inflated with LayoutInflater,and they contain TextView and ViewPager(that uses FragmentPagerAdapter).The problem is that only the first ViewPager shows fragments, and other ViewPagers just empty.</p>
  
  <p>MainActivity.class :</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ViewPager viewPager;
      LinearLayout linearLayout;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          linearLayout = (LinearLayout)findViewById(R.id.layout);
  
         for(int i = 0;i&lt;10;i++) {
  
          PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
          pagerAdapter.addFragment(new FragmentRed());
          pagerAdapter.addFragment(new FragmentYellow());
          pagerAdapter.addFragment(new FragmentGreen());
  
          View view = getLayoutInflater().inflate(R.layout.test_item, null);
  
          ViewPager viewPager = (ViewPager) view.findViewById(R.id.view_pager);
          viewPager.setAdapter(pagerAdapter);
  
          TextView textView = (TextView)view.findViewById(R.id.text_view);
          textView.setText("SampleText " + i);
  
          linearLayout.addView(view);
      }
  
      private class PagerAdapter extends FragmentPagerAdapter{
          ArrayList&lt;Fragment&gt;fragments = new ArrayList&lt;&gt;();
  
          public void addFragment(Fragment fragment){
              fragments.add(fragment);
          }
  
          public PagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public Fragment getItem(int position) {
              return fragments.get(position);
          }
  
          @Override
          public int getCount() {
              return fragments.size();
          }
      }
  </code></pre>
  
  <p>And this is what i get in the emulator :
  <a href="https://i.stack.imgur.com/SKFYM.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/SKFYM.jpg</a></p>
  
  <p>First ViewPager works fine, and i need to make others do so.</p>
  
  <p>test_item.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;TextView
          android:id="@+id/text_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;&lt;/TextView&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/view_pager"
          android:layout_width="match_parent"
          android:layout_height="100dp"&gt;&lt;/android.support.v4.view.ViewPager&gt;&gt;
  &lt;/LinearLayout&gt;
  </code></pre>