Nope. Try this. -Create a mutable bitmap the size of the screen. Save this bitmap as a variable of your instance. -Create a Canvas from this bitmap (i think you can 'cache' it, save this canvas as a variable of your instance). -Draw your touches into this canvas.
Then in the 'onDraw(Canvas screenCanvas)' draw the mutable bitmap into the screenCanvas. On May 5, 3:35 pm, Moons <[email protected]> wrote: > When you call View.invalidate(), your View refresh itself, wich means > that all your previous draws are erased. > > On May 5, 8:41 am, Sukitha Udugamasooriya <[email protected]> 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); > > } > > } > > > }- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

