我在尝试实现 OnTouchListener 时遇到错误:
The method onTouch(View, MotionEvent) of type new View.OnTouchListener(){} must override a superclass method
我不知道为什么它不起作用,因为我似乎正确地覆盖了该方法:
public class MyActivity extends Activity
{
...creation code etc...
OnTouchListener mTouchListener = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
...touch code...
}
}
}
关于如何调试这个有什么想法吗?
最佳答案
在 Eclipse 中,转至 Windows>Preference>Java>Compiler 并选择 1.6。
您可能正在使用 1.5,而 1.5 不允许在接口(interface)方法上使用 @Override,而只允许在父类(super class)方法上使用 @Override。 1.6 确实如此。
如果仍然不起作用,请删除@Override行...
public class MyActivity extends Activity
{
...creation code etc...
OnTouchListener mTouchListener = new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
...touch code...
}
}
}
关于android - OnTouchListener 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4316005/