I am trying to get a simple surface view to respond to touch events. The application below launches but does not respond to touch events. I have a Log.i statement to confirm (by printing to the console) whether or not the touch event is working. Can anyone tell me what I am doing wrong?
This is the my main activity
public class MainActivity extends Activity {
public static int screenWidth, screenHeight;
public static boolean running=true;
public static MainSurface mySurface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this gets the size of the screen
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
screenWidth = displaymetrics.widthPixels;
screenHeight = displaymetrics.heightPixels;
Log.i("MainActivity", Integer.toString(screenWidth) + " " + Integer.toString(screenHeight));
mySurface = new MainSurface(this);
setContentView(mySurface);
}
}
This is the surface view class
public class MainSurface extends SurfaceView implements OnTouchListener {
public MainSurface(Context context) {
super(context);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
int point = event.getPointerCount();
Log.i("MainSurface", Integer.toString(x)); //nothing prints to the console here
return true;
}
}