我有一个开关盒,如果按下登录按钮,它将移至下一个活动。但是,由于某种原因,它不起作用。

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btnAccSignup;
    private Button btnSignin;

    FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnAccSignup = (Button) findViewById(R.id.btnAccSignup);
        btnSignin = (Button) findViewById(R.id.btnSignin);
        btnSignin.setOnClickListener(this);

        mAuth = FirebaseAuth.getInstance();

    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnAccSignup:
                openSignupActivity(); // This part does not work. Everything else works fine.
                break;

            case R.id.btnSignin:
                userSignin();
                break;
        }
    }

    public void openSignupActivity() {
        Intent intent = new Intent(MainActivity.this, SignupActivity.class);
        startActivity(intent);
    }
}

最佳答案

您忘记为btnAccSignup添加监听器,而仅为btnSignin添加监听器。只需添加:

btnAccSignup.setOnClickListener(this);

关于java - 意向在switch语句中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49701253/

10-09 03:23