title: ViewPager SetCurrentItem does not set the position after it is clicked
body: <p>I'm using <a href="https://github.com/MikeOrtiz/TouchImageView" rel="nofollow">TouchImageView</a> to load images in full screen and have zoom/pinch capability.</p>
  
  <p>The images are pulled from URL via a web service. The response is in JSON. At this part, I'm using Volley+GSON to obtain the response and use a custom adapter to populate the Pager.</p>
  
  <p>Initially, the images are shown in a listview. When a user click an item, it will go full screen showing the chosen item.</p>
  
  <p>However, in my case, this doesn't happen. Whatever position the user chose, it will still show the image at index 0.</p>
  
  <p>Here is how I do it:</p>
  
  <p>In this adapter, a user will click an item and it will pass the <strong>position</strong> to another activity.</p>
  
  <pre><code>public class ItemPhotoAdapter extends BaseAdapter {
  
      private ArrayList&lt;ItemImageModel&gt; arrItemImage;
  
      @Override
      public ItemImageModel getItem(int i) {
          return arrItemImage.get(i);
      }
  
      ...
  
      @Override
      public View getView(int i, View view, ViewGroup viewGroup) {
          ViewHolder vh;
          lf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          if(view == null){
              vh = new ViewHolder();
              view = lf.inflate(R.layout.row_photo_grid, null);
              vh.item_image = (ImageView) view.findViewById(R.id.img_item);
  
              view.setTag(vh);
          } else {
              vh = (ViewHolder) view.getTag();
          }
  
  
          ItemImageModel iim = arrItemImage.get(i);
  
          Picasso.with(context) //
                  .load(iim.getResized()) //
                  .placeholder(R.drawable.placeholder) //
                  .error(R.drawable.error)
                  .into(vh.item_image);
  
          vh.item_image.setOnClickListener(new OnImageClickListener(i));
  
          return view;
      }
  
      ...
  
      private class OnImageClickListener implements View.OnClickListener {
          int _position;
  
          public OnImageClickListener(int position) {
              this._position = position;
          }
  
          @Override
          public void onClick(View view) {
              Intent i = new Intent(context, PhotoGalleryActivity.class);
              i.putExtra("position", _position);
              context.startActivity(i);
  
          }
      }
  }
  </code></pre>
  
  <p>In <code>PhotoGalleryActivity</code>, will load all the images back, but it doesn't start with the item the user chose.</p>
  
  <pre><code>public class PhotoGalleryActivity extends FragmentActivity {
  
      private ArrayList&lt;ItemImageModel&gt; arrItemImages;
  
      ...
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_photo_gallery);
  
          ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
          pb = (ProgressBar) findViewById(R.id.loading);
  
          ActionBar actionBar = getActionBar();
          actionBar.setDisplayHomeAsUpEnabled(true);
  
          arrItemImages = new ArrayList&lt;ItemImageModel&gt;();
  
          Intent i = getIntent();
          final int position = i.getIntExtra("position", 1);
          user_id = i.getStringExtra("user_id");
          item_id = i.getStringExtra("item_id");
  
  //        Log.d(TAG, "Image position: " + position);
  
          mAdapter = new PhotoGalleryAdapter(arrItemImages, getApplicationContext(), this);
  
          mViewPager.setAdapter(mAdapter);
  
          mViewPager.setCurrentItem(position);
  
          // ViewPagerIndicator
          CirclePageIndicator titleIndicator = (CirclePageIndicator)findViewById(R.id.titles);
          titleIndicator.setViewPager(mViewPager);
  
          loadPhotos();
      }
  
      ...
  
      private void loadPhotos() {
          mRequestQueue = Volley.newRequestQueue(this);
  
          String url = Constants.ITEM_DETAILS;
  
          GsonRequest&lt;ItemDetailContainer&gt; myReq = new GsonRequest&lt;ItemDetailContainer&gt;(
                  Request.Method.GET, url, ItemDetailContainer.class,
                  createMyReqSuccessListener(), createMyReqErrorListener());
  
          mRequestQueue.add(myReq);
      }
  
      ...
  }
  </code></pre>