How to draw line and erase previous line simultaneously on canvas [android]
<p>I am using canvas.</p>

<p>I am trying to draw line and erase previous line simultaneously but it's hidden behind the drawn line. So I want to draw line continuously and erase previous one. What thing is missing, and how can I solve that? Any help is welcome.</p>

<p><a href="http://i.stack.imgur.com/p1hf4.png" rel="nofollow">Here is a screen of the application</a></p>

<pre><code>public class DrawView extends View {
Paint paint = new Paint();
Path mPath, mPathErase;
Paint PaintWhite = new Paint();
float Rectpx, RectgetScanBarWidth, RectgetHeight;
int cnvasHight;
int cnvasWidth;


public DrawView(Context context) {
    super(context);
    paint.setColor(Color.GREEN);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.MITER);
    paint.setStrokeWidth(2f);
    mPath = new Path();
    mPathErase = new Path();

    PaintWhite.setColor(Color.WHITE);
    PaintWhite.setStyle(Paint.Style.STROKE);
    PaintWhite.setStrokeJoin(Paint.Join.MITER);
    PaintWhite.setStrokeWidth(4f);


}


public ContextObject plotingProcedure(ContextObject drow, float py) {
    System.out.println("counter:=" + Float.parseFloat(drow.getCounter().toString()) + " PX:-" + drow.getPx() + " Py:-" + drow.getPy());
    Rectpx = drow.getPx();
    RectgetScanBarWidth = drow.getScanBarWidth();
    RectgetHeight = drow.getHeight();
    drow.setPx(Float.parseFloat(drow.getCounter().toString()));
    drow.setPy(py);
    System.out.println("Rect Dim" + Rectpx + " , " + RectgetScanBarWidth + " , " + RectgetHeight);
    mPath.moveTo(drow.getOpx(), drow.getOpy());
    mPath.lineTo(drow.getPx(), drow.getPy());

    drow.setOpx(drow.getPx());
    drow.setOpy(drow.getPy());

    if (drow.getOpx() &gt; drow.getWidth()) {
        drow.setPx(0);
        drow.setOpx(0);
        drow.setCounter(0d);
    } else {
        System.out.println("counter after:======" + drow.getCounter());
        drow.setCounter(drow.getCounter() + drow.getSpeed());
    }
    drow.setCurrentsample(drow.getCurrentsample() + 1);


    invalidate();
    return drow;
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(5);
    canvas.drawRect(Rectpx, 0, Rectpx + RectgetScanBarWidth, RectgetHeight, paint);
    paint.setColor(Color.GREEN);
    paint.setStrokeWidth(5);
    canvas.drawPath(mPath, paint);
}

public int getCanvasHeigt() {
    return cnvasHight;
}

public void setCanvasHeigt(int cnvasHight) {
    this.cnvasHight = cnvasHight;
}

public int getCanvasWidth() {
    return cnvasWidth;
}

public void setCanvasWidth(int width) {
    this.cnvasWidth = width;
}
</code></pre>

<p>}</p>