title: need help to fix code for getting current view in viewpager
body: <p>Need help to fix a code I saw in a <a href="https://stackoverflow.com/a/9275732/1938357">https://stackoverflow.com/a/9275732/1938357</a>. The solution I need is get the current view onany page in my viewpager based application</p>
  
  <p>Below is the code for reference</p>
  
  <pre><code>public View getCurrentView(ViewPager pager) {
  for (int i = 0; i &lt; pager.getChildCount(); i++) {
      View child = pager.getChildAt(i);
      if (child.getX() &lt;= pager.getScrollX() + pager.getWidth()
           &amp;&amp; child.getX() + child.getWidth() &gt;= pager.getScrollX() + pager.getWidth()) {
          return child;
       }
  
   }
  return getChildAt(0);
  </code></pre>
  
  <p>I am trying to access the current view in the view pager and used the code above. It works fine when I scroll forwards. But when I scroll backwards then after 2 backward scrolls this stops working. </p>
  
  <pre><code>Public class myActivity extends FragmentActivity
  //Variable declarations
  protected void onCreate(Bundle savedInstanceState) {
  ViewPager mPager = (ViewPager) findViewById(R.id.pager);
  mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
  mPager.setAdapter(mPagerAdapter);
  View CurrView;
  
  OnPageChangeListener pageChangelistener = new OnPageChangeListener() {
    @Override
    public void onPageSelected(int pageSelected) {
      doTextViewChnges();//access the text view and update it based on pageSelected
      ---THIS IS WHERE I AM STUCK IN TRYING TO GET THE TEXTVIEW IN MY CURRENT FRAGMWNT/VIEW-------
   }
  
  mPager.setOnPageChangeListener(pageChangelistener);
  }
  private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 
    public ScreenSlidePagerAdapter(android.support.v4.app.FragmentManager  fm) {
      super(fm);
   }
  
   @Override
   public android.support.v4.app.Fragment getItem(int position) { 
      return ScreenSlidePageFragment.create(position, &lt;other parameters I want to pass&gt;);
   }
  
   @Override
   public int getCount() {
      return NUM_PAGES;
   }
  }  
  </code></pre>
  
  <p>And below is my ScreenSlidePageFragment class</p>
  
  <pre><code>public class ScreenSlidePageFragment extends android.support.v4.app.Fragment {
  
  public static final String ARG_PAGE = "pagenumber";
  public static final String ARG_PAGEARRAY = "pages";
  
  private int mPageNumber;
  //Declare other variables
  
  @SuppressLint("NewApi")
  public static ScreenSlidePageFragment create(int pageNumber, String[] pages, int bookmarkPageNumber, String storyName, int linesInOnePage) {
      ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
      Bundle args = new Bundle();
      args.putInt(ARG_PAGE, pageNumber);
      args.putStringArray(ARG_PAGEARRAY, pages);
      fragment.setArguments(args); 
      return fragment;
  }
  
  @SuppressLint("NewApi")
  public ScreenSlidePageFragment() {
  }
  
  @SuppressLint("NewApi")
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      mPageNumber = getArguments().getInt(ARG_PAGE);
      pages = getArguments().getStringArray(ARG_PAGEARRAY);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      rootView = (ViewGroup) inflater
              .inflate(R.layout.activity_story, container, false);
  
      //load layout with all components filled up for that page
      loadView(rootView);
      return rootView;
  }
  public int getPageNumber() {
      return mPageNumber;
  }
  </code></pre>