title: Display of Multiple pages in ViewPager, Incorrect Position
body: <p>I am trying to implement Dave Smith's PagerContainer to show multiple pages in my ViewPager. I have implemented an on-click listener to display the page numbers, but when I click on the left page, "clicked on item 2" message is shown (item 0 would be correct). If I click on the middle and the right pages, correct messages are displayed, "item 1" and "item 2" respectively. I've also attached an image to describe the problem. How can I fix this? Thanks in advance.</p>
  
  <p><img src="https://i.stack.imgur.com/ItFcd.png" alt="enter image description here"></p>
  
  <p>The code snippet is given below:</p>
  
  <pre><code>    @Override
      public Object instantiateItem(ViewGroup container, final int position) {
          TextView view = new TextView(PagerActivity.this);
          view.setText("Item "+position);
          view.setGravity(Gravity.CENTER);
          view.setBackgroundColor(Color.argb(255, position * 50, position * 10, position * 50));
  
  
          view.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
  
                  Toast.makeText(PagerActivity.this, "clicked on Item " + String.valueOf(position), 1000).show();
  
              }
          });
  
          container.addView(view);
          return view;
      }
  </code></pre>
  
  <hr>
  
  <pre><code>    pager.setOffscreenPageLimit(adapter.getCount());
  
      pager.setPageMargin(15);
  
      pager.setClipChildren(false);
  </code></pre>