title: Access TextView in ViewPager from Activity
body: <p>I have an Activity with a ViewPager containing multiple fragments. how can i now access a TextView in one of that fragments to change its text from the main activity? I tried multiple ways and they all ended in a NullPointerException.</p>
  
  <p>Activity:</p>
  
  <pre><code>public class SummonerOverview extends SherlockFragmentActivity implements TabListener, OnPageChangeListener {
  
  
      private ViewPager mPager;
      private PagerAdapter mAdapter;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.summoner_overview);
  
          initialize();   
      }
  
      private void initialize() {
  
          // initialize Pager
          mPager = (ViewPager) findViewById(R.id.viewpager);
          mAdapter = new PagerAdapter(getSupportFragmentManager());
          mPager.setAdapter(mAdapter);
          mPager.setCurrentItem(1);
          mPager.setOnPageChangeListener(this);
  
  
          }
  }
  </code></pre>
  
  <p>PagerAdapter:</p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter {
  
      public PagerAdapter(FragmentManager fm) {
          super(fm);
          frags = new Fragment[3];
          frags[0] = new StatisticsFragment(0);
          frags[1] = new RatingsFragment(1);
          frags[2] = new HistoryFragment(2);
      }
  
      private final int NUM_PAGES = 3;
      Fragment[] frags;
  
      @Override
      public Fragment getItem(int arg0) {
          if (arg0 == 0)
              return frags[0];
          else if (arg0 == 1)
              return frags[1];
          else
              return frags[2];
      }
      @Override
      public int getCount() {
          return NUM_PAGES;
      }
  
  }
  </code></pre>
  
  <p>The Fragment:</p>
  
  <pre><code>public class StatisticsFragment extends SherlockFragment {
  
  public StatisticsFragment(int fragNr) {
          this.fragNr = fragNr;
      }
  
  @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.fragment_overview_statistics, container, false);
  
          return v;
      }
  
  }
  </code></pre>
  
  <p>The Textview in the StatisticsFragment is labeled with an id in the fragment_overview_statistics.xml, but when i try</p>
  
  <pre><code>TextView tv = (TextView) findViewById(R.id.id_of_the_textview)
  tv.setText("text");
  </code></pre>
  
  <p>from within the onCreate() Method of the Activity after the initialize() Method, i get an Exception. </p>