title: Android Set Text of TextView in Fragment that is in FragmentPagerAdapter
body: <p>This one is driving me nuts. Basically, I want to create a <code>ViewPager</code> and add a few <code>Fragment</code>s to it. Then, all I want to do, it set a value in one of the <code>Fragment</code>'s <code>TextView</code>s. I can add the <code>Fragment</code>s fine, and they attach, but when I go to <code>findViewById()</code> for one of the <code>TextView</code>s in the first <code>Fragment</code> it throws a <code>NullPointerException</code>.  I, for the life of me, can't figure out why.</p>
  
  <p>Here's my code so far, let me know if more is needed please.</p>
  
  <pre><code>public class SheetActivity extends FragmentActivity {
  
      // /////////////////////////////////////////////////////////////////////////
      // Variable Declaration
      // /////////////////////////////////////////////////////////////////////////
      private ViewPager               viewPager;
      private PagerTitleStrip         titleStrip;
      private String                  type;
      private FragmentPagerAdapter    fragmentPager;  //UPDATE
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sheet);
  
          viewPager = (ViewPager) findViewById(R.id.viewPager);
          titleStrip = (PagerTitleStrip) findViewById(R.id.viewPagerTitleStrip);
  
          // Determine which type of sheet to create
          Intent intent = getIntent();
          this.type = intent.getStringExtra("type");
          FragmentManager manager = getSupportFragmentManager();
          switch (type) {
              case "1":
                  viewPager.setAdapter(new InstallAdapter(manager));
                  break;
              case "2":
                  viewPager.setAdapter(new InstallAdapter(manager));
                  break;
          }
          fragmentPager = (FragmentPagerAdapter) viewPager.getAdapter();  //UPDATE
      }
  
      @Override
      public void onResume() {
          super.onResume();
  
          fragmentPager.getItem(0).setText("something"); //UPDATE
      }
  
      class MyAdapter extends FragmentPagerAdapter {
  
          private final String[]      TITLES      = { "Title1", "Title2" };
          private final int           PAGE_COUNT  = TITLES.length;
          private ArrayList&lt;Fragment&gt; FRAGMENTS   = null;
  
          public MyAdapter(FragmentManager fm) {
              super(fm);
              FRAGMENTS = new ArrayList&lt;Fragment&gt;();
              FRAGMENTS.add(new FragmentA());
              FRAGMENTS.add(new FragmentB());
          }
  
          @Override
          public Fragment getItem(int pos) {
              return FRAGMENTS.get(pos);
          }
  
          @Override
          public int getCount() {
              return PAGE_COUNT;
          }
  
          @Override
          public CharSequence getPageTitle(int pos) {
              return TITLES[pos];
          }
      }
  }
  </code></pre>
  
  <p>All of <code>Fragment</code>s I created only have the <code>onCreateView()</code> method overridden so I can display the proper XML layout.  Other than that they are 'stock'.  Why can't I interact with elements in any of the <code>Fragment</code>s?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>So do something like this?</p>
  
  <pre><code>public class FragmentA extends Fragment {
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle inState) {
          return inflater.inflate(R.layout.fragment_a, container, false);
      }
  
      public void setText(String text) {
          TextView t = (TextView) getView().findViewById(R.id.someTextView);  //UPDATE
          t.setText(text);
      }
  }
  </code></pre>
  
  <p><strong>XML LAYOUT FOR FRAGMENT A</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/someTextView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:textSize="22sp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>