3

I´ve created a costum view, and on the onDrawMethod i´ve started to draw some things. A few rects,lines, and a text.

  canvas.drawText("Hello",150,150, paint);

Now, I want to change this text, after an OnTouchEvent.

My problem is, that I don´t know, how to remove the old text. At the moment my second text, which is shown after the TouchEvent, is just overlapping my old text. Should I redraw my hole view with the new text?

Kara
  • 6,115
  • 16
  • 50
  • 57
FireDragon
  • 33
  • 1
  • 3

1 Answers1

3

Typically you would redraw the entire view if a lot of things are going, but in this scenario you can just draw a box with the same color as the background over the old text, then display the new text on top of it.

If you have a background image, though, then it would be easier just to re-create the whole canvas.

methodin
  • 6,717
  • 1
  • 25
  • 27
  • A canvas is just a bitmap. Whatever you draw on it is permanent. There are ways to handle it but again most implementations just redraw the entire canvas on every pass. You could draw to two bitmap objects which are then drawn to the canvas every time in order, effectively giving you a "layers" approach. – methodin Dec 12 '10 at 19:21