我正在尝试实现OnTouchListener,但我一直收到以下错误: 此行有多个标记 - 无法解析OnTouchListener 一种类型 我看过其他类似的问题,他们的问题与OnTouchListener这个词的大写字母有关,我甚至试图导入android.view.View;但我仍然得到同样的错误。
import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
public class MySurfaceView extends SurfaceView implements Runnable, OnTouchListener{ //error
SurfaceHolder myHolder;
Thread myThread;
boolean isRunning=true;
public MySurfaceView(Context context) {
super(context);
// TODO Auto-generated constructor stub
myHolder = getHolder();
myThread = new Thread(this);
myThread.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while(isRunning)
{
if(!myHolder.getSurface().isValid())
continue;
Canvas canvas = myHolder.lockCanvas();
//////////////////////////////////////
canvas.drawARGB(255, 150, 150, 10);
//////////////////////////////////////
myHolder.unlockCanvasAndPost(canvas);
}
}
public void stop()
{
isRunning=false;
while(true)
{
try {
myThread.join();
break;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // block until thread dies
break;
}
}
public void start()
{
isRunning=true;
myThread = new Thread(this); // this it means it will use the run method
myThread.start();
}
public boolean onTouch(View v, MotionEvent event) {
return true;
}
}
答案 0 :(得分:1)
添加此导入
import android.view.View.OnTouchListener;