title: Get current position Pager Adapter onClickListener
body: <p>I have a problem with my Pager Adapter. I have an <code>ImageView</code> and <code>TextView</code> in layout inflater. My adapter will show some Image and description of the Image. And I want to implement <code>onClick</code> to the pager, when I click the Image, the <code>TextView</code> will show/hide.</p>
  
  <p>Below my snippet code : </p>
  
  <pre><code>private class MyAdapter extends PagerAdapter implements ViewPager.OnClickListener {
      private ArrayList&lt;Bitmap&gt; images;
      private LayoutInflater inflater;
      private Context context;
      private ViewPager viewPager;
  
      private TextView textViewDescription;
      private ImageView imageViewDescription;
  
      public MyAdapter(Context context, ArrayList&lt;Bitmap&gt; images, ViewPager viewPager) {
          this.context = context;
          this.images = images;
          this.viewPager = viewPager;
          inflater = LayoutInflater.from(context);
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          container.removeView((View) object);
      }
  
      @Override
      public int getCount() {
          return images.size();
      }
  
      @Override
      public Object instantiateItem(ViewGroup view, final int position) {
          LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View page = inflater.inflate(R.layout.item_image_preview, null);
  
          ImageView myImage = (ImageView) page.findViewById(R.id.imageView_preview);
          TextView textView= (TextView) page.findViewById(R.id.textView_image_description);
  
          textViewDescription = textView;
          imageViewDescription = myImage;
  
          imageDescription = arraydescription.get(position);
  
          textView.setText(arraydescription.get(position));
          myImage.setImageBitmap(images.get(position));
  
          page.setOnClickListener(new View.OnClickListener(){
              public void onClick(View v){
                  if (isDescriptionVisible) {
                      textViewDescription.setVisibility(View.GONE);
                  } else {
                      textViewDescription.setVisibility(View.VISIBLE);
                  }
                  isDescriptionVisible = !isDescriptionVisible;
  
                  Log.i("TAG", "This page was clicked: " + position);
              }
          });
  
          ((ViewPager) view).addView(page, 0);
          return page;
      }
  
      @Override
      public boolean isViewFromObject(View view, Object object) {
          return view.equals(object);
      }
  
      @Override
      public void onClick(View v) {
          if (isDescriptionVisible) {
              textViewDescription.setVisibility(View.GONE);
          } else {
              textViewDescription.setVisibility(View.VISIBLE);
          }
          isDescriptionVisible = !isDescriptionVisible;
      }
  }
  </code></pre>
  
  <p>The problem is: if the pager at position 2, and I click the Image, <code>TextView</code> at position 2 will show/hide. But when I slide into position 1 and I click the Image, the <code>TextView</code> which show/hide is still in position 2. Its like only one position that I can handle. I read <a href="https://stackoverflow.com/questions/16350987/viewpager-onitemclicklistener">a question about this example</a> but it is still not working.</p>