title: Viewpager onpageselected return wrong position
body: <p>I ran into some strange issue, whenever I'm trying to assign position to my textview, it goes very strange with the first and second page, it returns 0 for the first one and 0 for the second one, page three says 1, and whenever I swipe back to page 0 it says 1.</p>
  
  <p>Here is my activity (theabcactivity):</p>
  
  <pre><code>public class theabcactivity extends FragmentActivity {
  
  
  String[] heabc;
  int backColor;
  int currentnumber = 0;
  private ViewPager mPager;
  private PagerAdapter mPagerAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.content_theabcactivity);
  
      heabc = getResources().getStringArray(R.array.heabc);
  
  
  
  
      // Instantiate a ViewPager and a PagerAdapter.
      mPager = (ViewPager) findViewById(R.id.pager);
      mPager.setPageTransformer(true, new ZoomOutPageTransformer());
      mPagerAdapter = new 
      ScreenSlidePagerAdapter(getSupportFragmentManager());
      mPager.setAdapter(mPagerAdapter);
      mPager.setCurrentItem(0);
      mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
          }
  
          @Override
          public void onPageSelected(int CurPage) {
  
              currentnumber = CurPage;
                  Log.e("CurPage", " " + CurPage);
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
          }
      });
  }
  
  
  private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
      public ScreenSlidePagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          Random rnd = new Random();
          backColor = Color.argb(40, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
          return new theabc();
      }
      @Override
      public int getCount() {
          return heabc.length;
      }
  }
      }
  </code></pre>
  
  <p>Here I'm assigning the currentnumber = CurPage;, that I reuse later on at my fragment.</p>
  
  <p>Fragment code (theabc):</p>
  
  <pre><code>public class theabc extends Fragment {
  
  TextView itemscount;
  String [] heabc;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      ViewGroup rootView = (ViewGroup) inflater.inflate(
              R.layout.theabc, container, false);
  
      LinearLayout contentll = (LinearLayout)rootView.findViewById(R.id.content);
  
      heabc = getResources().getStringArray(R.array.heabc);
      itemscount = (TextView)rootView.findViewById(R.id.itemcount);
  
  
      theabcactivity abcact = (theabcactivity) getActivity();
      contentll.setBackgroundColor(abcact.backColor);
  
  
      itemscount.setText(String.valueOf(abcact.currentnumber));
      Log.e("www", "current number value" + abcact.currentnumber);
  
  
  
  
  
  
      return rootView;
  }
  
  
      }
  </code></pre>
  
  <p>One other thing i've noticed that whenever this activity opens up, it loads the fragment two times as I'm receiving the following Log:</p>
  
  <pre><code>E/www: current number value0
  E/www: current number value0
  </code></pre>
  
  <p>It leads me into conclusion that when Viewpager opens up it loads the first two items, the first one and the second one. 
  How can I solve that it would load the first item as 0, the next one 1 and so on?</p>
  
  <p>Thanks in advance.  </p>