I am cheating on 2D graphics in the Android SDK and I am having problems with what should be a simple example.
I assume that I am simply misunderstanding something fundamental / basic.
public class DrawView extends View {
Paint paint = new Paint();
Canvas canvas = new Canvas();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
this.canvas = canvas;
this.canvas.drawLine(0,0, 500, 500, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d("DrawView", "onTouchEvent: " + event.getX() + "," + event.getY() );
canvas.drawLine(0,500, 500, 0, paint);
return true;
}
}
When the application starts, the above code draws one line from 0,0to 500,500. These parts work great.

The problem is that the second line is not displayed in the touch event. onTouchEventdefinitely called because I see a message about debugging coordinates in the log.
Can someone point out what stupid thing I'm doing wrong?
source
share