title: Iterate through ViewPager views in Android
body: <p>I'm simply trying to iterate through the pages that I created with a ViewPager. Each page has a textview that I need to get the value of. I can get the current fragment, but I need to be able to specify the pages in my for loop, like this: </p>
  
  <pre><code>public void setEntryValues() {
  
          int numPages = mAdapter.getCount();
  
          JournalEntryFragment frag;
          View view;
          TextView txtView;
  
          for(int i = 0; i &lt; numPages; i++) {
  
              frag = (JournalEntryFragment)mAdapter.instantiateItem(mPager,mPager.getCurrentItem());
  
              //frag = (JournalEntryFragment)mAdapter.getItem(i); // Doesn't work, returns null for view
  
  
              view = frag.getView();
              txtView = (TextView)view.findViewById(R.id.scale);
              int scale = Integer.valueOf(txtView.getText().toString());
  
              Log.v("rx", "scale: " + scale);
  
              if(i == 0) {
                  mEntry.setPain(scale);
              } else if(i ==1) {
                  mEntry.setStress(scale);
              } else {
                  mEntry.setSleep(scale);
              }
  
              Log.v("rx", mEntry.toString());
  
  
          }
  
  
      }
  </code></pre>
  
  <p>getCurrentItem() works fine, but only for the current slide. When I try getItem(), I always get a null for the view.</p>
  
  <p>/* Update - Here is my FragmentPagerAdapter */</p>
  
  <pre><code>public class JournalPagerAdapter extends FragmentPagerAdapter {
  
      public JournalPagerAdapter(FragmentManager mgr) {
          super(mgr);
      }
      @Override
      public int getCount() {
          return(3);
      }
      @Override
      public Fragment getItem(int position) {
          return(JournalEntryFragment.newInstance(position));
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return super.getPageTitle(position);
      }
  
      @Override
      public int getItemPosition(Object object) {
          return super.getItemPosition(object);
      }
  
      @Override
      public long getItemId(int position) {
          return super.getItemId(position);
      }
  
  }
  </code></pre>