0
votes

I am trying to redraw the path covered on a view when a button is clicked. For this I have maintained a linked list of all the points covered by the touch event.But unfortunately nothing is draw on canvas. I have checked all the flows of control through print statements and they seemed to work fine. Please help me figure it out

The code in touch event is: x,y are event.getx(),event.gety() respectively

    switch(event.getAction()){
    case MotionEvent.ACTION_DOWN:
        path.moveTo(x, y);
        return true;
    case MotionEvent.ACTION_MOVE:
        path.lineTo(x, y);          
            ll.add(new Point((int) x, (int) y));
        break;
    default:
        return false;

The event handler for button is

public void onClick(View v) {
            setPractise = true;
            path.reset();
            postInvalidate();   
        }

The ondraw method is

protected void onDraw(Canvas canvas) {
    if(!setPractise){
    canvas.drawPath(path, pencil);
    }

    else
    {       
        while(( p =ll.getNext()) != null){
            x = (float)p.x;
            y = (float)p.y;
            canvas.drawLine(px, py, x, y, pencil);
            System.out.println("working"+"x is "+x+" y is "+y); 
            px =x;
            py = y;

        }
    }
}

The screen shot of present view

1
Why dont you draw it with a path?Mann
Its like I want to draw small circles on equidistant points on my path. so I had to try a linked listsandilya
What is with your pencil? Have you tried to draw a lone from for instance x=0 to x=100?Mann
ontouch succesfully draws. Problem only with button onclicksandilya
The clicklistener and the if clause are working correctly?Mann

1 Answers

0
votes

Try to call first the super method in your onDraw method:

super.onDraw(canvas);