本文介绍了尝试在builder.setPositiveButton的onClick()方法中放置一些代码时,获取“无法解析方法'addOnCompletionListener()'........"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在AlertDialog.Builderbuilder.setPositiveButton方法中放置一些代码.

I'm trying to place some code inside AlertDialog.Builder's builder.setPositiveButton method.

问题是我遇到以下错误:Cannot resolve method 'addOnCompletionListener(anonymous android.content.DialogInterface.OnClickListener, anonymous com.google.android.gms.tasks.OnCompletionListener<com.google.firebase.auth.AuthResult>)

The problem is that I'm getting the following error: 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,您应检查此方法需要什么样的参数,如果是Context,请尝试将其更改为此

"this" in this line means your DialogInterface.OnClickListener , you should check what kind of params this method needs, if Context, try to change it to this

addOnCompleteListener(YourActivityName.this, new OnCompleteListener<AuthResult>()

这篇关于尝试在builder.setPositiveButton的onClick()方法中放置一些代码时,获取“无法解析方法'addOnCompletionListener()'........"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:02