isuru isuru -4 years ago 227
Android Question

Cannot resolve method contains(int, int)?

I'm trying to check particular region contains touch points on

onTouchEvent
in Android. Initially I put my all the regions data in array as follows.

ArrayList<Region> regionlist = new ArrayList<>();

RectF rectF = new RectF();
path.computeBounds(rectF, true);
r = new Region();
r.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
regionlist.add(r);


Here is my
onTouchEvent
.

public boolean onTouchEvent(MotionEvent event) {

Point point = new Point();
point.x = (int) event.getX();
point.y = (int) event.getY();
invalidate();
Log.d(TAG, "point: " + point);


for( Object result : regionlist ) {
Log.d("isuru", "Bucha " + result);
if(result.contains(point.x, point.y)) { //Error Line
Log.d(TAG, "Touch IN");
}else {
Log.d(TAG, "Touch OUT");
}

}
return true;

}


As I mention in my code
contains
shows error as
Cannot resolve method contains(int, int)
? Why this happens?

Answer Source

Please change the following code

for( Object result : regionlist ) {
 //code
}

to

for( Region result : regionlist ) {
 //code
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download