I have some snippets that are added and removed from dynamic code RelativeLayout. one of the fragments is this ListFragment, and, like my other fragments with the Close and Save buttons, this list contains only the list.
My goal is to close / delete this fragment by clicking it out of place anywhere.
I found the following code:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Rect r = new Rect(0, 0, 0, 0);
this.getWindow().getDecorView().getHitRect(r);
boolean intersects = r.contains((int) event.getX(), (int) event.getY());
if (!intersects) {
this.finish();
return true;
}
}
return super.onTouchEvent(event);
}
This closes not full-screen activity when clicked outside, but I just don’t understand how to find the fragment rectangle.
Can someone help and point me in the right direction? Any help would be appreciated.
Thank.
source
share