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/58851145/

相关文章:

swift - 新的 FUITableViewDataSource - 如何使用? swift 3

java - dialogBu​​ilder.setMessage 为空

java - 无法在自定义 AlertDialog.Builder 上调用 Dismiss()

c# - 从 ViewModel 到 View Xamarin 的 MVVMCross Calling 函数

java - RxJava 如何订阅一个 Subject 到一个 Observable

android - 在线为Android应用程序VideoView存储视频

javascript - Firebasefunctions.auth.user().onCreate不触发

ubuntu 上的 Android sdk 管理器

android - 使用软键盘查看移动,阻止其他 UI 对象

ios - 通过电子邮件注册用户接受重复的电子邮件(firebase-swift)