Click here to Skip to main content
13,050,429 members (132,290 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(connected)
    	{
        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);
            _graphics.add(graphic);
            initial_x = event.getX();
            initial_y = event.getY();
 
            Canvas canvas = new Canvas();
            canvas.drawColor(Color.BLACK);
 
            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
halabella1.3K
Updated 20-Nov-12 20:00pm
TorstenH.34.9K
v4
Comments
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 | Mobile
Web02 | 2.8.170713.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2017
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