android - DialogInterface.OnShowListener() 无法解析为类型

标签 android

我正在与一位 friend 远程协作开发一个 Android 项目,当我将他的更改提取到我的本地存储库时,我收到以下针对 AlertDialog 对象调用的错误消息:

DialogInterface.OnShowListener() cannot be resolved to a type

完整代码如下:

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;
...
...
protected AlertDialog mDialogForgotPassword;
...
...
mDialogForgotPassword = new AlertDialog.Builder(LogInActivity.this)
.setTitle(getString(R.string.forgot_password))
.setView(input)
.setCancelable(false)
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        // NOTE: LEAVE THIS AS EMPTY
        // WE OVERRIDEN THIS METHOD USING THE setOnShowListener
    }

})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        dialog.cancel();
    }
})
.create(); // created AlertDialog

// ERROR APPEARS NEXT, red line under "new DialogInterface.OnShowListener()"
mDialogForgotPassword.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        final Button positiveButton = mDialogForgotPassword.getButton(AlertDialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String EMAIL = input.getText().toString();
                if( ValidationHelper.isEmail(EMAIL) ){
                    resetUserPassword(EMAIL);
                }
            }
        });
    }
}); // end setOnShowListener
mDialogForgotPassword.show();

friend 说当他在Eclipse中输入mDialogForgotPassword后按Ctrl + Space时,方法setOnShowListener() 作为建议出现。然而,对我来说,它没有,但导入语句似乎是完整的。帮忙?

最佳答案

如果您使用的是 Eclipse,请尝试按

CTRL + SHIFT + O

(它不是“零”,而是字母“O”),而在导致问题的文件中。这应该可以解决所有导入问题。

如果这没有帮助,那么您应该确保您和您的 friend 将项目配置为使用相同的 API 级别。 DialogInterface.OnShowListener() 从 API 级别 8 开始可用,因此请确保您的项目配置为至少使用该 API 级别。

关于android - DialogInterface.OnShowListener() 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11699511/

相关文章:

android - 在哪里可以找到 `Warnings found during shrinking` 的警告?

android - 使用 sqlite 开始使用 RxJava

java - 如何在 android studio 中的第二个 Activity 中显示单击的单选按钮值?

Android -- 检索默认系统字体字符串名称

android - 如何使用路由器通量将标签栏放在安卓屏幕的底部?

Android - 在以前没有的地方抛出致命异常

android - 如何写弯曲的文字?

Android:以固定间隔拉取位置崩溃,Looper Prepare(是的,我搜索过!!)

android - 如何在 Android 的 EditText 中输入特殊字符?

android - 如何检测 Android 中的假 GPS 坐标?