title: FragmentPagerAdapter doesn't recreate Fragments on orientation change?
body: <p>I have a <code>ViewPager</code> (extends <code>FragmentPagerAdapter</code>) which holds two <code>Fragments</code>. What I need is just refresh a <code>ListView</code> for each <code>Fragment</code> when I swipe among them. For this I have implemented <code>ViewPager.OnPageChangeListener</code> interface (namely <code>onPageScrollStateChanged</code>). In order to hold references to <code>Fragment</code>s I use a <code>HashTable</code>. I store references to <code>Fragments</code> in <code>HashTable</code> in <code>getItem()</code> method: </p>
  
  <pre><code>  @Override
          public Fragment getItem(int num) {
              if (num == 0) {
                  Fragment itemsListFragment = new ItemsListFragment();
                  mPageReferenceMap.put(num, itemsListFragment);
                  return itemsListFragment;
              } else {
                  Fragment favsListFragment = new ItemsFavsListFragment();
                  mPageReferenceMap.put(num, favsListFragment);
                  return favsListFragment;
              }
          }
  </code></pre>
  
  <p>So when I swipe from one <code>Fragment</code> to another the <code>onPageScrollStateChanged</code> triggers where I use the <code>HashTable</code> to call required method in both <code>Fragments</code> (refresh):</p>
  
  <pre><code> public void refreshList() {
          ((ItemsListFragment) mPageReferenceMap.get(0)).refresh();
          ((ItemsFavsListFragment) mPageReferenceMap.get(1)).refresh();
      }
  </code></pre>
  
  <p>Everything goes fine until <code>orientation change</code> event happens. After it the code in <code>refresh()</code> method, which is:</p>
  
  <pre><code>public void refresh() {
          mAdapter.changeCursor(mDbHelper.getAll());
          getListView().setItemChecked(-1, true); // The last row from a exception trace finishes here (my class).
      }
  </code></pre>
  
  <p>results in <code>IllegalStateException</code>:</p>
  
  <pre><code>java.lang.IllegalStateException: Content view not yet created
          at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
          at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
          at ebeletskiy.gmail.com.passwords.ui.ItemsFavsListFragment.refresh(ItemsFavsListFragment.java:17)
  </code></pre>
  
  <p>Assuming the <code>Content</code> view is not created indeed I set the <code>boolean</code> variable in <code>onActivityCreated()</code> method to <code>true</code> and used <code>if/else</code> condition to call <code>getListView()</code> or not, which shown the activity and content view successfully created.</p>
  
  <p>Then I was debugging to see when <code>FragmentPagerAdapter</code> invokes <code>getItem()</code> and it happens the method is not called after <code>orientation change</code> event. So looks like it <code>ViewPager</code> holds references to old <code>Fragments</code>. This is just my assumption. </p>
  
  <p>So, is there any way to enforce the <code>ViewPager</code> to call <code>getItem()</code> again, so I can use proper references to current <code>Fragments</code>? May be some other solution? Thank you very much. </p>