You can't just do the drawing when you need to register the touch event.
I'm assuming that
rect
is a member variable, but it doesn't follow the naming convention like your other variables. If it isn't a private member variable, then make it one.
You will need to override the
onDraw()
method of the view that you want to draw on.
protected void onDraw (Canvas canvas)
{
super.onDraw(canvas);
canvas.drawRect(rect, mPaint);
}