Android neue View mit OnTouchListener

Hallo Leute,
ich hab ein problem:
Ich habe meine eigene View erstellt, welche einen OnTouchListener besitzt, dies will aber leider nicht funktionieren.

Java:
	 public class MyView extends View {
     
		 Canvas c;
		 
		 public MyView(Context context) {
             super(context);
             // TODO Auto-generated constructor stub
             this.setOnTouchListener(new OnTouchListener()
		     {
		     public boolean onTouch(View v, MotionEvent event)
		     {
		    	 float X = event.getX();
		    	 float Y = event.getY();
		    	 
		    	 switch (event.getAction()) {
		         case MotionEvent.ACTION_DOWN: 
		        	 
		        	 c.drawColor(Color.BLACK);
		        	 Paint p = new Paint();
		        	 p.setColor(Color.WHITE);
		        	 c.drawCircle(X, Y, 30, p);
		             break;

		         case MotionEvent.ACTION_MOVE:
		             
		             break;

		         case MotionEvent.ACTION_UP:   
		             
		             break;
		     }

		         return true;
		     }
		     });
         }
         
		 
		 
		 
         @Override
         protected void onDraw(Canvas canvas) {
            c = canvas;
        	 // TODO Auto-generated method stub
            super.onDraw(canvas);
            int x = getWidth();
            int y = getHeight();
            canvas.drawColor(Color.BLACK);
        }
     }
 

Zurück
Oben