title: ViewPager + FragmentStatePagerAdapter: ViewPager stops working when screen orientation changes
body: <p>i am using ActionBarSherlock (which is basically an extension of the Android Support Package).</p>
  
  <p>What i'm trying to do is the following:</p>
  
  <p>I have a <code>FragmentActivity</code> which hosts just a single <code>ViewPager</code>. This <code>ViewPager</code> has a <code>FragmentStatePagerAdapter</code> (because there will be many items in the future). But for now it is just loaded with 2 items for testing.</p>
  
  <p>Everything is working just fine while i am in portrait orientation. But when i change so landscape orientation it switches back to the first item in the adapter (which is fine since everything is reloaded etc), but i am unable to swype to the next item. There is just nothing happening.</p>
  
  <p>From debugging i can see that the <code>Loader</code> return the two items just fine. <code>getItem(...)</code> is also called with <code>position</code> 0 and 1. So basicall everything looks fine, except it isn't ;)</p>
  
  <p>Btw: the same thing is happening vice versa when i start in landscape orienation and switch to portrait orientation.</p>
  
  <p>Any ideas what might be wrong here?</p>
  
  <p>Here is some of my code:</p>
  
  <pre><code>public class QuotesStatePagerAdapter extends FragmentStatePagerAdapter {
  
  private List&lt;Quote&gt; mQuotes;
  
  public QuotesStatePagerAdapter(FragmentManager fm, List&lt;Quote&gt; quotes) {
      super(fm);
      mQuotes = quotes;
  }
  
  @Override
  public Fragment getItem(int position) {
      Bundle arguments = new Bundle();
      arguments.putSerializable("quote", mQuotes.get(position));
      QuoteFragment fragment = new QuoteFragment();
      fragment.setArguments(arguments);
      return fragment;
  }
  
  @Override
  public int getCount() {
      return mQuotes.size();
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public QuotesFragment() {
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  public void updateOrdering(ORDERING newOrdering) {
      mOrdering = newOrdering;
      getLoaderManager().getLoader(0).startLoading();
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      return inflater.inflate(R.layout.quotes, container, false);
  }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      super.onViewCreated(view, savedInstanceState);
      mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
      mViewPager.setOnPageChangeListener(this);
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      getLoaderManager().initLoader(0, null, this);
  }
  
  @Override
  public Loader&lt;List&lt;Quote&gt;&gt; onCreateLoader(int id, Bundle args) {
      return new QuotesLoader(getActivity(), mCategoryId);
  }
  
  @Override
  public void onLoadFinished(Loader&lt;List&lt;Quote&gt;&gt; loader, List&lt;Quote&gt; data) {
      mQuotes = data;
      mViewPager.setAdapter(new QuotesStatePagerAdapter(
              getSupportFragmentManager(), mQuotes));
  }
  </code></pre>