我正在与一个朋友在一个 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();
这位朋友说,当他在 Eclipse 中键入后按Ctrl
+时,该方法会显示为建议。然而,对我来说,它没有,但导入语句似乎是完整的。帮助?Space
mDialogForgotPassword
setOnShowListener()