title: Issue with BackStack method and ViewPager in android
body: <p>I have an activity which contains a framelayout. In it, I have a fragment which contains the ViewPager with two different fragments inside. When I push the button in the given fragment, I replace the framelayout container with a new fragment. Now when I press back the ViewPager view is not restored, it's gone. </p>
  
  <p>This is the first fragment:</p>
  
  <pre><code>public class CurrencyFragment extends BaseFragment {
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setHasOptionsMenu(true);
      }
  
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  
          super.onCreateOptionsMenu(menu, inflater);
  
      }
  
      // onclick method for the refresh button on the action bar
      // the method itself calls the anoteher method getCurrency()
      // it also sets visibility to progress bar and loading text and
      // sets invisible to the listview
  
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
          case R.id.action_refresh:
  
  
              Log.i("TAG", "refresh pressed =&gt;");
              return true;
          }
          // Handle your other action bar items...
  
          return super.onOptionsItemSelected(item);
      }
  
  
  
      // oncreateView() where the basic view is created
  
      @Override
      public View onCreateView(final LayoutInflater inflater,
              ViewGroup container, Bundle savedInstanceState) {
          final View view = inflater.inflate(R.layout.fragment_currency_layout,
                  container, false);
  
  
  
          mBankName = (TextView) view.findViewById(R.id.Currency_name);
          mBuySell = (LinearLayout) view.findViewById(R.id.Buy_Sell);
          mButtonBuy = (TextView) view.findViewById(R.id.Button_buy);
          mButtonSell = (TextView) view.findViewById(R.id.Button_sell);
          mViewpager = (ViewPager) view.findViewById(R.id.Detailpager);
  
  
  
          Bundle bundle = getArguments();
          if(bundle != null){
          Bank object = (Bank) bundle.getSerializable("message");
          mBankName.setText(object.getName());
          code = object.getCode();
          }
  
          testadapter = new ViewPagerAdapter(getFragmentManager(),code);
          mViewpager.setAdapter(testadapter);
  
          if(code.equals("NBG")){
              mBuySell.setVisibility(View.GONE);
               mViewpager.setOnTouchListener(new View.OnTouchListener() {
  
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      // TODO Auto-generated method stub
                      return false;
                  }
              });
          }else{
              mBuySell.setVisibility(View.VISIBLE);
          }
  
          mViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
              @Override
              public void onPageSelected(int position) {
                  // TODO Auto-generated method stub
                  if (position == 0){
                      mButtonBuy.setBackgroundColor(Color.parseColor("#2FCEB8"));
                      mButtonSell.setBackgroundColor(Color.parseColor("#333333"));
                  }
                  else{
                      mButtonSell.setBackgroundColor(Color.parseColor("#2FCEB8"));
                      mButtonBuy.setBackgroundColor(Color.parseColor("#333333"));
                  }
              }
  
              @Override
              public void onPageScrollStateChanged(int arg0) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void onPageScrolled(int arg0, float arg1, int arg2) {
                  // TODO Auto-generated method stub
  
              }
  
  
          });
  
  
  
  
  
          mButtonBuy.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  mButtonBuy.setBackgroundColor(Color.parseColor("#2FCEB8"));
                  mButtonSell.setBackgroundColor(Color.parseColor("#333333"));
                  mViewpager.setCurrentItem(0);
  
  
  
              }
          });
  
          mButtonSell.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  mButtonSell.setBackgroundColor(Color.parseColor("#2FCEB8"));
                  mButtonBuy.setBackgroundColor(Color.parseColor("#333333"));
                  mViewpager.setCurrentItem(1);
  
  
              }
          });
  
          return view;
  
      }  
  
  }
  </code></pre>
  
  <p>after is replaced with the other</p>
  
  <pre><code>public class DetailedCalculator extends BaseFragment {
  
      private View detailedView;
      private TextView mButtonBuy;
      private TextView mButtonSell;
      private TextView mDetailedBank;
      private ViewPager mDetailpager;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
  
          DetailPagerAdapter myAdapter = new DetailPagerAdapter(getFragmentManager());
  
          detailedView = inflater.inflate(R.layout.detail_buy_sell, container, false);
          mButtonBuy = (TextView) detailedView.findViewById(R.id.Detail_buying);
          mButtonSell = (TextView) detailedView.findViewById(R.id.Detail_selling);
          mDetailedBank = (TextView) detailedView.findViewById(R.id.Detail_BankNAme);
  
          mDetailpager = (ViewPager) detailedView.findViewById(R.id.Detailpager);
          mDetailpager.setAdapter(myAdapter);
  
  
          mDetailpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
              @Override
              public void onPageSelected(int position) {
                  // TODO Auto-generated method stub
                  if(position == 0){
                      mButtonBuy.setBackgroundColor(Color.parseColor("#2FCEB8"));
                      mButtonSell.setBackgroundColor(Color.parseColor("#333333"));
                  }
                  else{
                      mButtonSell.setBackgroundColor(Color.parseColor("#2FCEB8"));
                      mButtonBuy.setBackgroundColor(Color.parseColor("#333333"));
                  }
              }
  
              @Override
              public void onPageScrolled(int arg0, float arg1, int arg2) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void onPageScrollStateChanged(int arg0) {
                  // TODO Auto-generated method stub
  
              }
          });
  
          mButtonBuy.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  mButtonBuy.setBackgroundColor(Color.parseColor("#2FCEB8"));
                  mButtonSell.setBackgroundColor(Color.parseColor("#333333"));
                  mDetailpager.setCurrentItem(0);
              }
          });
  
          mButtonSell.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  mButtonSell.setBackgroundColor(Color.parseColor("#2FCEB8"));
                  mButtonBuy.setBackgroundColor(Color.parseColor("#333333"));
                  mDetailpager.setCurrentItem(1);
  
              }
          });
  
  
          return detailedView;
  
  
      }
  
  
  
  }
  </code></pre>