Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Java Android
Android. I have added onTouchEvent in my main class and it works ok when I switched to SurfaceView. I need to draw some graphics on it.
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            GraphicObject graphic = new GraphicObject(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
            graphic.getCoordinates().setX((int) event.getX() - graphic.getGraphic().getWidth() / 2);
            graphic.getCoordinates().setY((int) event.getY() - graphic.getGraphic().getHeight() / 2);
            initial_x = event.getX();
            initial_y = event.getY();
            Canvas canvas = new Canvas();
            Bitmap bitmap;
            GraphicObject.Coordinates coords;
                bitmap = graphic.getGraphic();
                coords = graphic.getCoordinates();
                canvas.drawBitmap(bitmap, 50, 50, null);
    	return super.onTouchEvent(event);
Does'nt draw anything. Please help.
Posted 20-Nov-12 8:34am
Edited 20-Nov-12 20:00pm
TorstenH. at 21-Nov-12 2:00am
I added an Android tag - might be helpful.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid