我试图在 AlertDialog.Builder
中放置一些代码的 builder.setPositiveButton
方法。
问题是我收到以下错误:Cannot resolve method 'addOnCompletionListener(anonymous android.content.DialogInterface.OnClickListener, anonymous com.google.android.gms.tasks.OnCompletionListener<com.google.firebase.auth.AuthResult>)
代码如下:
AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
builder.setTitle("Title");
builder.setView(R.layout.customlayout);
builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//error from below line
mAuth.createUserWithEmailAndPassword(userEmail.getText().toString(), userPassword.getText().toString())
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d("signUpSuccessful", "createUserWithEmail:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Snackbar snackbar = Snackbar
.make(coordinatorLayout, "Sign up failed. Please retry.", Snackbar.LENGTH_SHORT);
snackbar.show();
}
// ...
}
});
//upto this line
}
});
AlertDialog dialog = builder.create();
dialog.show();
这里有什么问题吗?
请告诉我。
最佳答案
addOnCompleteListener(this, new OnCompleteListener<AuthResult>()
这一行的“this”是指你的 DialogInterface.OnClickListener ,你应该检查这个方法需要什么样的参数,如果是上下文,试着把它改成这个
addOnCompleteListener(YourActivityName.this, new OnCompleteListener<AuthResult>()
关于android - 尝试在 builder.setPositiveButton 的 onClick() 方法中放置一些代码时获取 'Cannot resolve method ' addOnCompletionListener( )'.......',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58851145/