I have implemented tic tac toe game as it is from api samples.from that tic tac toe game i would like to draw a bitmap instead of lines.I have written a peace of code as follows at onTouchEvent:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
RectF rct=_logic.getPositionToFill(event.getX(), event.getY());
if(rct!=null)
{
if(_drawX)
{
_bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.smile);
_canvas.drawBitmap(_bitmap, 0.0f, 0.0f, _paint);
/* _canvas.drawLine(rct.left, rct.top,
rct.right, rct.bottom, _paint);
_canvas.drawLine(rct.right, rct.top,
rct.left, rct.bottom, _paint);*/
}
else
{
_bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.sad);
_canvas.drawBitmap(_bitmap, 0.0f, 0.0f, _paint);
// _canvas.drawOval(rct, _paint);
}
_drawX=!_drawX;
invalidate();
}
}
return true;
}
I have inserted some code at if block instead of drawLine.
I don’t know why are you drawing the lines in the onTouchEvent method. In the on onTouchEvent method you just only need to take the cordinates of the touch and draw the picture into onDraw method.