Click here to Skip to main content
Rate this: bad
good
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(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
Edited 20-Nov-12 20:00pm
TorstenH.32.7K
v4
Comments
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)

  Print Answers RSS
0 Maciej Los 450
1 OriginalGriff 403
2 Sergey Alexandrovich Kryukov 189
3 CPallini 189
4 CHill60 180
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,972
2 Maciej Los 3,269
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
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