0
我試圖實現OnTouchListener但我不斷收到以下錯誤:在該行 多個標記 - OnTouchListener解決不了 的類型 我已經看過其他類似的問題和他們的問題與大寫有關單詞OnTouchListener的字母,我甚至試圖導入android.view.View;但我仍然得到相同的錯誤。如何實現OnTouchListener?
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;
}
}
謝謝, – Jakson