title: Updating fragments from Activity in a ViewPager
body: <p>I'm new to Android developing and I would really appreciate some help here.</p>
  
  <p>I'm using a fragment that contains a TextView and I'm using 5 instances of the same MyFragment class. </p>
  
  <p>In the activity, i got a button and a ViewPager, and I need the button to update all the fragment instances content, whenever its clicked. </p>
  
  <p>Here's the Activity</p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
  
  final static String[] CONTENT = {"a", "b"};
  ViewPager pager;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      List&lt;MyFragment&gt; fragments = new Vector&lt;MyFragment&gt;();
      for(int i = 0; i &lt; 5; i++){
          MyFragment fragment = new MyFragment(CONTENT);
          fragments.add(fragment);
      }
      PagerAdapter adapter = new PagerAdapter(this.getSupportFragmentManager(), fragments);
      pager = (ViewPager) findViewById(R.id.viewpager);
      pager.setAdapter(adapter);
  
      Button button = (Button) findViewById(R.id.button);
      button.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              //method that isn't working
              PagerAdapter adapter = (PagerAdapter)pager.getAdapter();
              for(int i = 0; i &lt; 5; i++){
                  MyFragment fragment = (MyFragment) adapter.getItem(i);
                  fragment.textView.setText(fragment.content[1]);
              }
          }
      });
  }
  }
  </code></pre>
  
  <p>The Fragment</p>
  
  <pre><code>public class MyFragment extends Fragment{
  
  String[] content;
      TextView textView;
  
  public MyFragment(String[] content) {
      this.content = content;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_content, container, false);
      textView = (TextView) view.findViewById(R.id.textView1);
      textView.setText(content[0]);
      return view;
  }
  
  }
  </code></pre>
  
  <p>And the FragmentPagerAdapter</p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter{
  
  List&lt;MyFragment&gt; fragments;
  
  public PagerAdapter(FragmentManager fm, List&lt;MyFragment&gt; fragments) {
      super(fm);
      this.fragments = fragments;
  }
  
  @Override
  public Fragment getItem(int arg0) {
      return fragments.get(arg0);
  }
  
  @Override
  public int getCount() {
      return fragments.size();
  }
  
  }
  </code></pre>
  
  <p>The OnClick method gives me a NullPointerException whenever i try to access a fragment from the adapter which is less than adapter.getCurrentItem() - 1, or more than adapter.getCurrentItem() + 1.</p>
  
  <p>Any idea on how to update all the fragments at the same time?</p>
  
  <p>Thanks in advance.</p>