title: ViewPager and PagerAdapter, get Drawable
body: <p>Hello I have a <strong>ViewPager</strong> binded to a custom <strong>PagerAdapter</strong>. </p>
  
  <p>The layout only has an <strong>ImageView</strong> and I would like to get the drawable of this imageView, on a button press. I added this method to the <strong>PagerAdapter</strong>:</p>
  
  <pre><code>public Drawable getDrawable() {
      return imageView.getDrawable();
  }
  </code></pre>
  
  <p>In the <strong>Activity</strong>, on the button click, I execute this:</p>
  
  <pre><code>((MyAdapter)(mViewPager.getAdapter())).getDrawable();
  </code></pre>
  
  <p>The problem is that I obtain the forward image and not the current one, as I would like.</p>
  
  <p>How to solve this?</p>
  
  <pre><code>public class MyAdapter extends PagerAdapter {
   private final ArrayList&lt;Images&gt; mImages;
   private Context context;
   private ImageView imageView;
  
  
  public MyAdapter(Context context, ArrayList&lt;Images&gt; images) {
      this.context = context;
      mImages = images;
  }
  
  public Drawable getDrawable() {
      return imageView.getDrawable();
  }
  
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
      imageView = (ImageView) view.findViewById(R.id.iv);
  
      final String image = mImages.get(position).getFilename();
  
      Context context = imageView.getContext();
      final int width = ImageGalleryUtils.getScreenWidth(context);
  
      if (!TextUtils.isEmpty(image)) {
          Picasso.with(imageView.getContext())
                  .load(image)
                  into(imageView); 
      } else {
          imageView.setImageDrawable(null);
      }
   return view;
  }
  
  @Override
  public int getCount() {
      return mImages.size();
  }
  }
  </code></pre>