Wednesday, May 16, 2012

OnTouch method in OnDraw

I need to set an onTouch method to the rect that I have set up but I dont know how to do this in an OnDraw method. this but I dont know how here my code, Thanks for the help!



public class Tab3 extends View implements OnTouchListener
{
int x1, x2, y1, y2;
Rect Rect = new Rect();
public Tab3(Context context, AttributeSet attrs)
{
super (context, attrs);
x1 = 0;
x2 = 100;
y1 = 0;
y2 = 100;

}

@Override
protected void onDraw(Canvas canvas)
{
// TODO Auto-generated method stub
super.onDraw(canvas);


Rect.set(x1, y1, x2, y2);

Paint blue = new Paint();
blue.setColor(Color.BLUE);
canvas.drawRect(Rect, blue);
}

@Override
public boolean onTouch(View v, MotionEvent event)
{

return false;
}
}




No comments:

Post a Comment