possible duplicate
Hello friends,
I creating paint application, I have problem in that. If I draw the rectangle without fill and or another like bound area a
here is the code (you have to bound the shape on touch event otherwise it change the color of shape works):
public class ttt extends View {
MyShape myShape;
public ttt(Context context) {
super(context);
// TODO Auto-generated constructor stub
myShape = new MyShape();
Paint paint = new Paint();
paint.setColor(Color.WHITE);
myShape.setPaint(paint);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
myShape.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
int x = (int) event.getX();
int y = (int) event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Paint paint = new Paint();
paint.setColor(Color.BLUE);
myShape.setPaint(paint);
invalidate();
break;
default:
break;
}
return super.onTouchEvent(event);
}
class MyShape {
private Paint paint;
public MyShape() {
// TODO Auto-generated constructor stub
}
public void onDraw(Canvas canvas){
canvas.drawCircle(15, 15, 30, getPaint());
}
/**
* @param paint the paint to set
*/
public void setPaint(Paint paint) {
this.paint = paint;
}
/**
* @return the paint
*/
public Paint getPaint() {
return paint;
}
}
}