title: How to call some method for Fragment which is in FragmentPagerAdapter?
body: <p>I have following issue. I have <code>ViewPager</code> and <code>FragmentPagerAdapter</code> for it. </p>
  
  <p>All I need to do is call some method from my <code>Fragment</code> which is in <code>ViewPager</code> when this page was selected.</p>
  
  <p>I tried to keep all my Fragments in <code>List</code> inside my adapter, but the problem is that when I rotate my device Adapter use previous fragments. New fragments were created after rotation and I have list of them, but I don't now how to get access to previous fragments. I have references to new fragments only.</p>
  
  <p>Here is my adapter:</p>
  
  <pre><code>public class MainPagerAdapter extends FragmentPagerAdapter {
      private List&lt;Fragment&gt; fragmentList;
  
      public MainPagerAdapter(FragmentManager fm) {
          super(fm);
          fragmentList = new ArrayList&lt;Fragment&gt;();
          fragmentList.add(new TaskPageFragment());
          fragmentList.add(new HistoryFragment());
          fragmentList.add(new TestFragment());
      }
  
      @Override
      public Fragment getItem(int i) {
          return fragmentList.get(i);
      }
  
      @Override
      public int getCount() {
          return 3;
      }
  }
  </code></pre>
  
  <p>Of course when I trying to access to fragment which was only created like an object, I can't get access to Activity Context.</p>
  
  <pre><code>Fragment fragment = pagerAdapter.getItem(i);
  if (fragment instanceof SelectionListener) {
       ((SelectionListener)fragment).onTabSelected();
  }
  </code></pre>
  
  <p>Here is <code>onTabSelected()</code> method call is shown. It's my interface which I implemented to each fragment in <code>ViewPager</code> and when it gets called after screen rotation I get null <code>Context</code></p>