title: How to move from second fragment to first fragment after click on button?
body: <p>I created a view pager in that two fragments are used to  move from one fragment to second fragment. In second fragment page I want the following: 
  when I click on button, fragments are changed from second to first one fragment; in view pager means second page to first page. First and second fragment have own XML file, and view pager is in main fragment's XML file. </p>
  
  <p>Means:</p>
  
  <ol>
  <li><code>class ViewPagerMainActivity extends FragmentActivity</code> contains main xml file that contain ViewPager</li>
  <li>First and Second fragment class extends fragment and have own design xml file</li>
  </ol>
  
  <p>Now I need to move from second to first fragment. How can I do this?</p>
  
  <p>My <code>ViewPagerMainActivity</code> is the following</p>
  
  <pre><code> public class CopyOfViewPagerMainActivity extends FragmentActivity implements
      OnClickListener, OnPageChangeListener {
  
  Button btnBack, btnNextImage;
  LinearLayout llMainPager;
  TelephonyManager telemamanger;
  TextView txtOpname, txtCharge;
  String operatorCodeName;
  int level = -1;
  double scale;
  int rawlevel;
  LinearLayout llayoutMainpager;
  int image;
  ViewPager pager;
  Boolean flagzoom, flagscale, flagfade, flagdepth, flagnone, flagpivot,
          flag3d;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.view_pager_main);
  
  
      // my  other code here
  
  }
  
  private class MyPagerAdapter extends FragmentPagerAdapter {
  
      public MyPagerAdapter(
              android.support.v4.app.FragmentManager fragmentManager) {
          super(fragmentManager);
      }
  
      @Override
      public Fragment getItem(int pos) {
          switch (pos) {
  
          case 0:
              return FirstFragment.newInstance("");
  
          case 1:
              return SecondFragment.newInstance("");
  
          default:
              return SecondFragment.newInstance("Default");
          }
      }
  
      @Override
      public int getCount() {
          return 2; // return no of fragment created by us
      }
  }
  
  @Override
  public void onClick(View v) {
  
  }
  
  @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
  
  }
  
  @Override
  public void onPageSelected(int arg0) {
      // TODO Auto-generated method stub
  
  }
  }
  </code></pre>
  
  <p>My first fragment following </p>
  
  <pre><code>public class CopyOfFirstFragment extends Fragment implements OnTouchListener ,OnPageChangeListener{
  
  String permanentval = "";
  LinearLayout llayoutslide;
  LinearLayout llayoutpassword;
  int image;
  TextView txtTime, txtDay, txtmissedCall, txtChargePercent,txtSMS;
  ImageView imgCharge;
  int charge;
  Boolean flagAnimzoom;
  ViewPager pchange;
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View v = inflater
              .inflate(R.layout.sliding_lock_pager, container, false);
  
      // my all code here
              return v;
  }
  
  public static CopyOfFirstFragment newInstance(String text) {
  
      CopyOfFirstFragment f = new CopyOfFirstFragment();
      Bundle b = new Bundle();
      b.putString("msg", text);
      f.setArguments(b);
  
      return f;
  }
  
  @Override
  public boolean onTouch(View v, MotionEvent event) {
      return false;
  }
  
  @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
  
  }
  
  @Override
  public void onPageSelected(int arg0) {
      // TODO Auto-generated method stub
  
  }
  
  
  }
  </code></pre>
  
  <p>My second fragment</p>
  
  <pre><code>public class CopyOfSecondFragment extends Fragment implements OnClickListener {
  
      LinearLayout llayoutPasswordEnter,llayoutPasswordConfirm,llayoutPasswordPager;
      Button btnNext, btnOne, btnTwo, btnThree, btnFour, btnFive, btnSix,
              btnSeven, btnEight, btnNine, btnZero;
      TextView txtClear, txtDone;
      String store = "";
      int one = 0, two = 0;
      String permanentval = "";
      RelativeLayout rlayoutPasswordEnter;
      int image;
      private Vibrator vibrator;
      Boolean getflagvibrate=false, getflagSounds=false;
      MediaPlayer mp;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.password, container,
                  false);
  
          // all code here
          txtDone.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  // in this button i want to move from this fragment to first means i want to display   firt xml file instead of this second one   &lt;----- here want to move 
              }
          });
  
          return v;
      }
      public void setButtonSize(Button btn) {
          int width = Constant.getDeviceWidth(getActivity()) / 5;
          LayoutParams params = new LayoutParams(width, width);
          params.leftMargin = 8;
          params.rightMargin = 8;
          btn.setLayoutParams(params);
      }
  
      public static CopyOfSecondFragment newInstance(String text) {
  
          CopyOfSecondFragment f = new CopyOfSecondFragment();
          Bundle b = new Bundle();
          b.putString("msg", text);
          f.setArguments(b);
          return f;
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>