You're overwriting the previous line each time you touch so the
application can only draw one line.
As far as I know each onDraw() call clears the screen and, therefore,
your previous strokes.

Take a look at the Path class, this provides an easy way of chaining
together multiple points into one long line.



On May 5, 7:43 am, Sukitha Udugamasooriya <suk...@gmail.com> wrote:
> Hi all,
>
> I'm relatively new to Android. I want to draw strokes on my screen
> when the user touches. Next stroke should be drawn from the end point
> of the previous stroke.
> This is my code. What happens here is just only the current stroke is
> drawn. Previous strokes are vanished? What is wrong here? Please
> help..
>
> package src.test;
>
> import android.app.Activity;
> import android.content.Context;
> import android.graphics.Bitmap;
> import android.graphics.Canvas;
> import android.graphics.Color;
> import android.graphics.Paint;
> import android.os.Bundle;
> import android.view.MotionEvent;
> import android.view.View;
> import android.view.View.OnTouchListener;
>
> public class ActDraw extends Activity implements OnTouchListener {
>
>     float x = 200;
>     float y = 200;
>     float x1 = 10;
>     float y1 = 45;
>     float prvx = 150;
>     float prvy = 150;
>     MyView m;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>
>         m = new MyView(this);
>         m.setOnTouchListener(this);
>         setContentView(m);
>
>     }
>     public boolean onTouch(View v, MotionEvent event) {
>         switch (event.getAction()) {
>         case MotionEvent.ACTION_DOWN: {
>             prvx = x;
>             prvy = y;
>             x = event.getX();
>             y = event.getY();
>              m.invalidate();
>         }
>         }
>         return false;
>     }
>
>     class MyView extends View {
>         Paint p = new Paint();
>         Bitmap bm;
>         int i;
>
>         public MyView(Context context) {
>             super(context);
>
>         }
>
>         @Override
>         protected void onDraw(Canvas canvas) {
>             super.onDraw(canvas);
>             p.setColor(Color.GREEN);
>             p.setStrokeWidth(4);
>             canvas.drawLine(prvx, prvy, x, y, p);
>         }
>     }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to