I have two custom views of Child (Relative Layout) and Parent (FrameLayout). When a single click occurs, I would like the child process to handle the event, but then still pass it on to the parents, and for any other event in the Child, just pass it on without processing.
The child view is set to match_parent.
This is what I still have:
public class Child extends RelativeLayout implements View.OnTouchListener {
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
}
public boolean onTouch(View view, MotionEvent motionEvent) {
return true;
}
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
gestrDetect_.onTouchEvent(e);
return super.dispatchTouchEvent(e);
}
}
public class Parent extends FrameLayout {
public Parent(Context context, AttributeSet attrs) {
super(context, attrs);
setOnTouchListener(this);
}
@Override
public boolean onTouch(View view, MotionEvent event) {
return gestrDetect_.onTouchEvent(event);
}
}
As long as I get single events in the child view, all other events, such as fling or scale, are not passed to the parent element. What is the correct way to handle a specific subset of events in a child, but still pass some of them to the parent?
Edit
I changed the code to the following:
public class Child extends RelativeLayout implements View.OnTouchListener {
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(android.view.MotionEvent e1, android.view.MotionEvent e2, float velocityX, float velocityY) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
}
public boolean onTouch(View view, MotionEvent motionEvent) {
return gestrDetect_.onTouchEvent(e);
}
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
return super.dispatchTouchEvent(e);
}
}
public class Parent extends FrameLayout {
@Override
public boolean onTouch(View view, MotionEvent event) {
return gestrDetect_.onTouchEvent(event);
}
}
.
@Override
public boolean onDown(MotionEvent e) {
return true;
}
to
return false;
singleTapUp .