title: How to move next page in android fragment tab using view pager?
body: <p>I have two tabs.Login and Register fragment. I have register button click in login tab and when I click, it should move to register fragment
  I used this method in LoginActivity</p>
  
  <pre><code>public void setCurrentItem(int item, boolean smoothScroll) {
      mPager.setCurrentItem(item, smoothScroll);
  }
  </code></pre>
  
  <p>and I get that method in Login fragment but it displays error.<br>
  My code is as follows: </p>
  
  <pre><code>public class LoginActivity extends SherlockFragmentActivity {
  
      private ViewPager mPager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // Get the view from activity_main.xml
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.loginpager);
          PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
          tabs.setIndicatorColor(Color.BLUE);
          tabs.setIndicatorHeight(5);
          mPager = (ViewPager) findViewById(R.id.pager);
          ViewPagerAdapter adapter = new ViewPagerAdapter(fm);
          mPager.setAdapter(adapter);
          tabs.setViewPager(mPager);
  
      }
  
      public void setCurrentItem(int item, boolean smoothScroll) {
          mPager.setCurrentItem(item, smoothScroll);
      }
  
      public class ViewPagerAdapter extends FragmentPagerAdapter {
  
          public ViewPagerAdapter(android.support.v4.app.FragmentManager fm) {
              super(fm);
          }
  
          private final String[] TITLES = { "LOG IN", "REGISTER" };
  
          @Override
          public CharSequence getPageTitle(int position) {
              return TITLES[position];
          }
  
          @Override
          public SherlockFragment getItem(int arg0) {
              switch (arg0) {
              // Open LoginFragment
              case 0:
                  LoginFragment loginfragment = new LoginFragment();
                  return loginfragment;
  
              // Open RegisterFragment
              case 1:
                  RegisterFragment registerfragment= new RegisterFragment();
                  return registerfragment;
  
              }
          return null;
          }
  
          @Override
          public int getCount() {
              return TITLES.length;
          }
  
      } 
  }
  </code></pre>
  
  <p><strong>LoginFragment:</strong></p>
  
  <pre><code>public class LoginFragment extends SherlockFragment implements OnClickListener {
  
      private LoginActivity loginActivity;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          // Get the view from fragmenttab3.xml
          View view = inflater.inflate(R.layout.login, container, false);
          SpannableString spannableString = new SpannableString(text);
          spannableString.setSpan(new ForegroundColorSpan(Color.BLACK), 24, 32, 0);
          ClickableSpan clickableSpan = new SpaceAdjust(text) {
              @Override
              public void onClick(View textView) {
                  loginActivity = new LoginActivity();
                  loginActivity.setCurrentItem(2, true); // here i am getting error. How to swipe to RegisterFragment
              }
          };
          spannableString.setSpan(clickableSpan, 24, 32, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
          dontHaveAccountRegister.setText(spannableString);
          dontHaveAccountRegister.setMovementMethod(LinkMovementMethod.getInstance());
          return view;
      }
  }
  </code></pre>
  
  <p><strong>Error :</strong></p>
  
  <pre><code>12-12 00:41:53.906: E/AndroidRuntime(1580): FATAL EXCEPTION: main
  12-12 00:41:53.906: E/AndroidRuntime(1580): Process: com.a.b, PID: 1580
  12-12 00:41:53.906: E/AndroidRuntime(1580): java.lang.NullPointerException
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at com.a.b.LoginActivity.setCurrentItem(LoginActivity.java:148)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at com.a.b.views.LoginFragment$5.onClick(LoginFragment.java:250)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:217)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at android.widget.TextView.onTouchEvent(TextView.java:7724)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at android.view.View.dispatchTouchEvent(View.java:7690)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
  12-12 00:41:53.906: E/AndroidRuntime(1580):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
  </code></pre>