2012-07-28 29 views
1

我正在与Android项目上的朋友进行远程协作,并且当我将其更改导入到本地回购库时,出现以下错误消息,用于对AlertDialog对象:DialogInterface.OnShowListener()无法解析为类型

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(); 

朋友说,当他输入mDialogForgotPasswordsetOnShowListener()显示为一个建议的方法后,按下Ctrl + Space在Eclipse。然而,对我而言,这并不是,但是进口报表似乎已经完整。帮帮我?

回答

0

我做了什么,以消除错误:

  1. 确信在Eclipse中我的Java编译器设置为1.6。右键单击项目 - > Java编译器 - >选中“启用项目特定设置” - >将“编译器合规性级别”设置为1.6 - >选中“使用默认编译器合规性设置”。

  2. 右键单击项目 - > Android - >勾选“Android 4.1”作为项目构建目标。在撰写本文时,Jelly Bean是最新版本。

  3. 在我的Android清单中,我将最低SDK升级到8(Froyo,2.2),并将targetSdk设置为16,Jelly Bean。无论如何,API等级4过低都是最低的,并且根据Android distribution data,其市场份额非常小且不断缩小。

1

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

CTRL + SHIFT + O 

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

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

+0

恐怕这两个解决方案都不起作用。我右键单击项目 - >属性 - > Android,我的目标版本实际上是API级别13.但是,在清单中,最小SDK设置为4,最大值设置为15。 – 2012-07-28 09:21:17