title: setCurrentItem in Viewpager don't Works
body: <p>I'm creating a gallery app and i'm using viewpager to show photos.</p>
  
  <p>Class of the list of images.</p>
  
  <pre><code>import android.content.Context;
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.GridLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  
  public class FotosList extends AppCompatActivity {
  
      public static FotosList m;
  
      private final Integer image_ids[] = {
              R.drawable.foto1,
              R.drawable.foto2,
              R.drawable.foto3,
              R.drawable.foto4,
              R.drawable.foto5,
              R.drawable.foto6,
              R.drawable.foto8,
              R.drawable.foto9,
              R.drawable.foto10,
              R.drawable.foto11,
              R.drawable.foto12,
              R.drawable.foto13,
              R.drawable.foto14,
              R.drawable.foto15
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          m=this;
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_fotos_list);
  
          RecyclerView recyclerView = (RecyclerView)findViewById(R.id.imagegallery);
          recyclerView.setHasFixedSize(true);
  
          RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(),2);
          recyclerView.setLayoutManager(layoutManager);
          ArrayList&lt;CreateList&gt; createLists = prepareData();
          MyAdapter adapter = new MyAdapter(getApplicationContext(), createLists);
          recyclerView.setAdapter(adapter);
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
  
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          finish();
          return true;
      }
  
      public class CreateList {
  
          private String image_title;
          private Integer image_id;
          public Integer getImage_ID() {
              return image_id;
          }
  
          public void setImage_ID(Integer android_image_url) {
              this.image_id = android_image_url;
          }
      }
  
      private ArrayList&lt;CreateList&gt; prepareData(){
  
          ArrayList&lt;CreateList&gt; theimage = new ArrayList&lt;&gt;();
          for(int i = 0; i&lt; image_ids.length; i++){
              CreateList createList = new CreateList();
              createList.setImage_ID(image_ids[i]);
              theimage.add(createList);
          }
          return theimage;
      }
  
      public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
          private ArrayList&lt;CreateList&gt; galleryList;
          private Context context;
  
          public MyAdapter(Context context, ArrayList&lt;CreateList&gt; galleryList) {
              this.galleryList = galleryList;
              this.context = context;
          }
  
          @Override
          public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
              View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cell_layout, viewGroup, false);
              return new ViewHolder(view);
          }
  
          @Override
          public void onBindViewHolder(MyAdapter.ViewHolder viewHolder,final int i) {
              viewHolder.img.setScaleType(ImageView.ScaleType.CENTER_CROP);
              viewHolder.img.setImageResource((galleryList.get(i).getImage_ID()));
              viewHolder.img.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      Intent in = new Intent(FotosList.m, Fotos.class);
                      in.putExtra("img",galleryList.get(i).getImage_ID());
                      m.startActivity(in);
                  }
              });
          }
  
          @Override
          public int getItemCount() {
              return galleryList.size();
          }
  
          public class ViewHolder extends RecyclerView.ViewHolder{
              private TextView title;
              private ImageView img;
              public ViewHolder(View view) {
                  super(view);
  
                  title = (TextView)view.findViewById(R.id.title);
                  img = (ImageView) view.findViewById(R.id.img);
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Class of viewPager:</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.os.Bundle;
  import android.support.v4.view.PagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import uk.co.senab.photoview.PhotoViewAttacher;
  
  public class Fotos extends Activity {
  
      int[] mResources = {
              R.drawable.foto1,
              R.drawable.foto2,
              R.drawable.foto3,
              R.drawable.foto4,
              R.drawable.foto5,
              R.drawable.foto6,
              R.drawable.foto8,
              R.drawable.foto9,
              R.drawable.foto10,
              R.drawable.foto11,
              R.drawable.foto12,
              R.drawable.foto13,
              R.drawable.foto14,
              R.drawable.foto15
      };
  
      int foto;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_fotos);
  
          CustomPagerAdapter mCustomPagerAdapter = new CustomPagerAdapter(this);
  
          ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager);
          mViewPager.setAdapter(mCustomPagerAdapter);
  
  
          try {
              foto = getIntent().getIntExtra("img", 0);
              mViewPager.setCurrentItem(foto);
          } catch (Exception e) {
          }
  
      }
  
  
      public class CustomPagerAdapter extends PagerAdapter {
  
          Context mContext;
          LayoutInflater mLayoutInflater;
          PhotoViewAttacher mAttacher;
  
          public CustomPagerAdapter(Context context) {
              mContext = context;
              mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          }
  
          @Override
          public int getCount() {
              return mResources.length;
          }
  
          @Override
          public boolean isViewFromObject(View view, Object object) {
              return view == ((LinearLayout) object);
          }
  
          @Override
          public Object instantiateItem(ViewGroup container, int position) {
              View itemView = mLayoutInflater.inflate(R.layout.pager_item, container, false);
  
              ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
              imageView.setImageResource(mResources[position]);
  
              mAttacher = new PhotoViewAttacher(imageView);
  
  
              container.addView(itemView);
  
              return itemView;
          }
  
          @Override
          public void destroyItem(ViewGroup container, int position, Object object) {
              container.removeView((LinearLayout) object);
          }
      }
  
  }
  </code></pre>
  
  <p>On click on a photo to open the viewpager with image...
  His open the last image...
  How to open clicked image</p>