I draw line with canvas and touch But my problem is this that when we toch again the screen , the perivious line deleted I want with touch again draw new line but the last line dont deleted Tnx protected void onDraw(Canvas canvas) { super.onDraw(canvas); // draw the mPath with the mPaint on the canvas when onDraw canvas.drawLine(sX, sY, eX, eY, mPaint); }
// when ACTION_DOWN start touch according to the x,y values
private void startTouch(float x, float y) {
sX = x;
sY = y;
}
// when ACTION_MOVE move touch according to the x,y values
private void moveTouch(float x, float y) {
eX = x;
eY = y;
}
private void upTouch(float x, float y) {
eX = x;
eY = y;
}
public void clearCanvas() {
invalidate();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startTouch(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
moveTouch(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
upTouch(x,y);
invalidate();
break;
}
return true;
}