我有两个片段,分别为SignInFragmentSignUpFragment。首先MainActivity使用此代码调用SignInFragment

//MainActivity
if (savedInstanceState == null) {
    signInFragment = new SignInFragment();
    signUpFragment = new SignUpFragment();

    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.frame_holder,signInFragment);
    fragmentTransaction.commit();
}


单击SignUpFragment中的注册按钮后,如何呼叫SignInFragment。我对按钮有参考:

//SignInFragment
Button buttonSignUp = view.findViewById(R.id.button_sign_up);

最佳答案

您需要先覆盖onClick的注册按钮。

并将这段代码放在里面

      FragmentTransaction fragmentTransaction =
              getSupportFragmentManager().beginTransaction();
              fragmentTransaction.replace(R.id.frame_holder, signInFragment);
              fragmentTransaction.commit();


sudhanshu-vohra所述,您必须替换它,而不要将其添加到frame_holder

07-24 13:49