title: Android - Access TextView inside ViewPager
body: <p>I am using the standard Viewpager with custom PageAdapter.</p>
  
  <p>How can I access to the Viewpager's TextView, to change the font color at onPageSelected()?</p>
  
  <h1>Edit 1: ViewPager Listener</h1>
  
  <pre><code>final ViewPager vp = (ViewPager) findViewById(R.id.a2viewpager);
          vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
              public void onPageScrollStateChanged(int arg0) {
  
              }
              public void onPageScrolled(int arg0, float arg1, int arg2) {
                  vp.getParent().requestDisallowInterceptTouchEvent(true);
              }
              public void onPageSelected(final int currentPage) {
                  ImageButton leftNav = (ImageButton) findViewById(R.id.a2left_nav);
                  ImageButton rightNav = (ImageButton) findViewById(R.id.a2right_nav);
                  int lastIdx = vpAadapter.getCount() - 1;
  
  
                  if (receiptPool.get(currentPage).contains("_(Canceled)") == true){
                      vp.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorRed));
                  }
                  else {
                      vp.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorMainTextBackground));
                  }
  
  
              }
          });
  </code></pre>
  
  <h1>Edit 1:  Custom Adapter</h1>
  
  <pre><code>public class CustomPagerAdapter extends PagerAdapter {
  
      Context mContext;
      private Vector&lt;View&gt; pages;
      private activity1 act1;
      private activity2 act2;
      private Intent intent;
  
      public CustomPagerAdapter(Context context, Vector&lt;View&gt; pages) {
          super();
          this.act1 = new activity1();
          this.act2 = new activity2();
          this.mContext=context;
          this.pages=pages;
      }
  
  
      @Override
      public Object instantiateItem(final ViewGroup container, final int CurrentPage) {
          View page = pages.get(CurrentPage);
  
          page.setOnTouchListener(new View.OnTouchListener() {
              /******/
  
          });
  
          container.addView(page);
          return page;
      }
  
  
      @Override
      public int getCount() {
          return pages.size();
      }
  
      @Override
      public boolean isViewFromObject(View view, Object object) {
          return view.equals(object);
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          container.removeView((View) object);
      }
  
      @Override
      public int getItemPosition(Object object) {
          // Seems to be required as a workaround.
          return POSITION_NONE;
      }
  }
  </code></pre>
  
  <p>Thanks</p>