如何实现 OnTouchListener ?
how to implement the OnTouchListener ?
我正在尝试实现 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;
}
}
添加这个导入
import android.view.View.OnTouchListener;
我正在尝试实现 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;
}
}
添加这个导入
import android.view.View.OnTouchListener;