I would like to know when will the method
protected void onDraw(final Canvas canvas) {}
will be called. I am asking about the control flow.constructor of this class is called from other class.When control comes to the constructor will it simply call all methods in this class??
Also i want to do some drawing when the draw image is touched and moved. for that i used onTouchEvent(MotionEvent event).But i dont know how to invoke onDraw after i do some coding in onTouch.That is i do change some coordinate values how will call onDraw to redraw image?
Can anyone help?
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
// TODO Auto-generated constructor stub
super(context);
}
@Override
protected void onDraw(final Canvas canvas) {
// TODO Auto-generated method stub
paint.setColor(Color.BLACK);
paint.setStrokeWidth(3);
canvas.drawRect(30, 350, 50, 400, paint);
super.onDraw(canvas);
// some other drawings
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN://some code
break;
case MotionEvent.ACTION_MOVE://some code
break;
case MotionEvent.ACTION_UP://some code
break;
default: break;
}
return super.onTouchEvent(event);
}
}
/**
* @author rajeshcp
*/
Call Invalidate when ever you want onDraw method to get called.