Click here to Skip to main content
11,496,146 members (614 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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 9:34am
halabella1.3K
Edited 20-Nov-12 21:00pm
TorstenH.34.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 RyanDev 230
1 Sergey Alexandrovich Kryukov 114
2 Richard Deeming 100
3 OriginalGriff 89
4 Mostafa Asaduzzaman 59
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2015
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