views:

18

answers:

1

Hi,

I hava a MapView and I define a Rect. Touching the map I compare the coordinates to detect whether the rect is touched or not. But it does not work

RectF hitTestRecr = new RectF();
hitTestRecr.set(0,100,0,100);
hitTestRecr.offset(0,0);

if (hitTestRecr.contains(event.getX(),event.getY())) {
    Toast.makeText(getBaseContext(), "hit", Toast.LENGTH_SHORT).show(); 
}else{
    Toast.makeText(getBaseContext(), "no hit", Toast.LENGTH_SHORT).show(); 
}

I always get no hit

any ideas?

A: 

It's because your RectF is 0 wide and 0 tall.

set(float left, float top, float right, float bottom)

I think what you want is

hitTestRecr.set(0,0,100,100);
CaseyB