how to draw ECG wave form in android using canvas
<p>i try to draw wave form using canvas method. unfortunately i get current position to end position but i need to full wave to show in view. </p>

<p>MainActivity</p>

<pre><code>public class LineView extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_line_view);

}
</code></pre>

<p>XML</p>

<pre><code> &lt;LinearLayout android:orientation="vertical"
    android:layout_height="350dp"
    android:layout_width="fill_parent"&gt;

&lt;com.akasmedical.android.linedrawing.DemoView
    android:layout_height="match_parent"
    android:layout_width="wrap_content"/&gt;
</code></pre>

<p>`   </p>

<p>My view is here</p>

<pre><code>public class DemoView extends View {
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
int x = 35, j = 35;
int i = 0;
//ECG Wave form
int[] a = {20, 50, 40, 65, 56, 43, 22, 23, 55, 77, 76, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25};

public DemoView(Context context) {
    super(context);
    init();
}

public DemoView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public DemoView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();

}

public void init() {
    paint.setColor(Color.WHITE);
    paint1.setColor(Color.RED);
}

@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    try {
        Thread.sleep(50);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    if (i != 0) {
        //draw wave form here
        canvas.drawLine(x, (getHeight() / 4) - a[i], x + 1, (getHeight() / 4) - a[i - 1], paint1);
        System.out.println(x);
    }
    i++;
    if (i == 22) {
        i = 0;
    }
    //Repaint wave form
    if (x &gt; getWidth() - 25) {
        canvas.drawRect(j, 0, j + 20, getHeight(), paint);
        j += 4;
        if (j &gt; getWidth() - 25)
            j = 35;
    } else {
        x += 4;
    }
    invalidate();
}}
</code></pre>

<p>Expected output like here</p>

<p><img src="https://i.stack.imgur.com/IMXJr.png" alt=""></p>

<p>I need to not only current to end position. i want previous position also draw in view activity. </p>