Click here to Skip to main content
13,401,763 members (51,607 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 9:34am
Updated 20-Nov-12 21:00pm
TorstenH. 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180218.2 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100