Android - line drawing

I want to draw a line on the screen to listen to the touch listener, but when I try to draw the line again, it erases the previous line. I am using the code below.

I can not find a solution to the problem. Please, help.

public class Drawer extends View
{
     public Drawer(Context context)
     {
         super(context);
     }

     protected void onDraw(Canvas canvas)
     {
         Paint p = new Paint();
         p.setColor(colordraw);
         canvas.drawLine(x1, y1, x2 , y2, p);
         invalidate();
     }
}
0
source share
1 answer

u can draw a line using a canvas object, but trying to draw a second line using a bitmap object trying to draw using a canvas object

 protected void onDraw(Canvas canvas)

 {
     Paint p = new Paint();
     p.setColor(colordraw);
     p.setColor(Color.BLUE);
     canvas.drawLine(x1, y1, x2 , y2, p);
     canvas.drawLine(x1, y1, x2 , y2, p);
     invalidate();
 }
0
source

All Articles