0
如果在我的onStart()上點擊一個按鈕以檢查點擊的按鈕是註冊還是登錄,我該如何放置if else語句?Android onStart如果點擊按鈕
這裏是我的代碼
public void onClick(View v) {
switch (v.getId()) {
case R.id.register:
i = new Intent(this, RegisterCustomer.class);
startActivity(i);
finish();
break;
case R.id.login:
final String email = memail.getText().toString();
final String password = mpassword.getText().toString();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(CustomerLoginActivty.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(CustomerLoginActivty.this, "sign in error", Toast.LENGTH_SHORT).show();
}
}
});
break;
}
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(firebaseAuthListener);
}
你想達到什麼樣的? –
嘗試在我的onStart()上放一個if if來檢查正在單擊的按鈕。可能嗎? – osoda
'onStart()'已經被調用。你能不能在你的'onClick()'中放置'mAuth.addAuthStateListener(firebaseAuthListener);'? – codeMagic