在尝试将一些代码放在builder.setPositiveButton的onClick()方法中时,获取'无法解析方法'addOnCompletionListener()'.......'

时间:2016-09-14 09:27:03

标签: android firebase android-alertdialog firebase-authentication

我正在尝试在AlertDialog.Builder的{​​{1}}方法中放置一些代码。

问题是我收到以下错误:builder.setPositiveButton

以下是代码:

Cannot resolve method 'addOnCompletionListener(anonymous android.content.DialogInterface.OnClickListener, anonymous com.google.android.gms.tasks.OnCompletionListener<com.google.firebase.auth.AuthResult>)

这里有什么问题?

请告诉我。

2 个答案:

答案 0 :(得分:22)

addOnCompleteListener(this, new OnCompleteListener<AuthResult>()

&#34;这&#34;在这一行中意味着你的DialogInterface.OnClickListener,你应该检查这个方法需要什么类型的params,如果是Context,试着把它改成这个

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

答案 1 :(得分:3)

您的问题出现在此行代码中:

Messenger

此处.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 参数编译器将您的活动上下文设为this

enter image description here

Solutin非常简单:

.OnClickListener

.addOnCompleteListener(ActivityName.this, new OnCompleteListener<AuthResult>() { 使用this