为什么eclipse总是高亮一个方法?
我正在尝试重写 onItemClick 方法。我将把我的导入和方法放在下面:
import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class ListViewActivityActivity extends ListActivity implements OnItemClickListener {
@Override
public void onItemClick(AdapterView adview, View target, int position, long id) {}
}
我的问题是为什么 onItemClick 方法不断下划线?我做错了什么? 我尝试重新加载项目,但没有帮助。有人遇到同样的问题吗?
PS,当我将鼠标悬停在它上面时,它会显示:ListViewActivityActivity 类型的方法 onItemClick(AdapterView, View, int, long) 必须重写超类方法
I am trying to override the method onItemClick. I will put my imports and methods below:
import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class ListViewActivityActivity extends ListActivity implements OnItemClickListener {
@Override
public void onItemClick(AdapterView adview, View target, int position, long id) {}
}
My question is why does onItemClick method keep underlining? What am I doing wrong?
I tried reloading project and it didn't help. Anybody run in to the same problem?
PS when I hover over it it says : The method onItemClick(AdapterView, View, int, long) of type ListViewActivityActivity must override a superclass method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的项目将 Java 编译器级别设置为 1.5。 Java 1.5 中实现接口方法的类不允许使用
@Override
注解;仅从 Java 1.6 开始允许这样做。进入项目属性(项目的上下文菜单),选择
Java Compiler
并将编译器合规级别设置为 1.6。Your project has the Java compiler level set to 1.5. The
@Override
annotation is not allowed for a class implementing an interface method in Java 1.5; this is only allowed from Java 1.6 onward.Go into your project properties (project's context menu), select
Java Compiler
and set the compiler compliance level to 1.6.您正在使用 AdapterView 的非泛型类型,但原始方法使用泛型类型。编译器允许,但不推荐。
这是重写
onItemClick
的正确方法:You are using the non-generic type of
AdapterView
but the original method uses a generic type. It is allowed by the compiler, but not recommended.This is the right way to override
onItemClick
: