android - 尝试在 builder.setPositiveButton 的 onClick() 方法中放置一些代码时获取 'Cannot resolve method ' addOnCompletionListener( )'.......'

标签 android firebase android-alertdialog firebase-authentication

我试图在 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/39486937/

相关文章:

android - GmsCore_OpenSSL 会导致所有更新的应用程序被 Google Play 拒绝吗?

firebase - 在 flutter 中合并来自 Firestore 的流

android - Dialogox 中的按钮单击监听器问题

java - 如何知道我的 Android 警报对话框何时被取消?

java - 如何从 TextView 结果获取值到 Alertdialog

android - 扩展 Android Systrace 工具

Java - Android - 将 Activity/Class 拆分为多个文件以便更好地组织(解决方案)

java - 更改 Min Sdk 版本后 "Cannot resolve symbol ' R '"?

java - 当数据库中没有条目时, if (dataSnapshot.getValue() == null) 返回 true,但在完成 "if"部分后也运行 else 部分

javascript - 在 Firebase 中存储 ID 列表