title: Android - Backstack while replacing fragment in ViewPager
body: <p>I'm creating ViewPager with three viewsin it. On the first view is a ListView, where onItemClick replaces that fragment new fragment with WebView in it. And I have two problems: when adding 'transaction.addToBackStack(null)', or 'transaction.setCustomAnimations(...)' Fragment with WebView stopps to show. Without these lines it shows, but I can't do BACK button to return to list.</p>
  
  <p>I was creating code based on <a href="http://tamsler.blogspot.com/2011/10/android-viewpager-and-fragments.html" rel="nofollow noreferrer">that tutorial</a> and <a href="https://stackoverflow.com/questions/7723964/replace-fragment-inside-a-viewpager">this SO question</a>. In that question there is used PagerAdapter, and I'm using FragmentPagerAdapter. Also I don't need more fragments to be replaced. It can be only once (from list to webView and back).</p>
  
  <p>Here is my adapter's code:</p>
  
  <pre><code>public Fragment getItem( int position )
  {
      Fragment fragment = null;
      switch ( position )
      {
          case 0: // news
              if ( mFragmentAtPos0 == null )
              {
                  mFragmentAtPos0 = new NewsListFragment( new FirstPageFragmentListener()
                  {
                      @Override
                      public void onSwitchToNewsFragment( String url, ViewGroup container )
                      {
                          FragmentTransaction transaction = fm.beginTransaction();
                          transaction.setCustomAnimations( R.anim.rotate_in, R.anim.rotate_out, R.anim.rotate_in, R.anim.rotate_out );
  
                          WebViewFragment wv = new WebViewFragment( url, context );
                          transaction.replace( container.getId(), wv );
                          transaction.commit();
  
                          mFragmentAtPos0 = wv;
                          notifyDataSetChanged();
                      }
                  } );
              }
              fragment = mFragmentAtPos0;
              break;
          case 1: 
              fragment = new NewsInfoFragment( context, true );
              break;
          case 2: 
              fragment = new NewsInfoFragment( context, false );
              break;
      }
      return fragment;
  }
  </code></pre>
  
  <p>and snippet from onCreateView() of that List's fragment:</p>
  
  <pre><code>listView.setOnItemClickListener( new OnItemClickListener()
      {
          @Override
          public void onItemClick( AdapterView&lt;?&gt; parent, View view, int position, long id )
          {
              if ( position &lt; listNewsAdapter.getCount() - 1 )
              {
                  if ( listener != null )
                  {
                      listener.onSwitchToNewsFragment( listNewsAdapter.getItem( position ).getNewsUrl(), container );
                  }
              }
          }
      } );
  </code></pre>