Intent在switch语句中不起作用

时间:2018-04-06 21:32:26

标签: java android

我有一个开关盒,如果按下signin按钮,它应该移动到下一个Activity。但是,由于某些原因它不起作用。

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);
    }
}

1 个答案:

答案 0 :(得分:1)

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

btnAccSignup.setOnClickListener(this);