how to swipe parent view(constrain layout) by swiping child views(edittext) in android java

Viewed 35
ConstraintLayout constraintLayout = (ConstraintLayout) findViewById(R.id.parent);
for (int i = 0; i < 5; i++) {
  EditText editText = new EditText(Home.this);
  constraintLayout.addView(editText);
}
constraintLayout .setOnTouchListener(new Home.OnSwipeTouchListener(Home.this) {
  @Override
  public void onSwipeLeft() {
    Toast.makeText(getApplicationContext(), "parent swipe", Toast.LENGTH_LONG).show();
  }
});

I want to add on swipe left and right event, but when I try,constrain layout is not swiping instead edittext is poping keyboard. I searched for this problem I got solution that use onintercepttouchevent but I don't know how to use it with my code and where to call this function

1 Answers

This is a case of when need to return false for onTouchListener of the EditText indicating the EditText didn't consume the event and that it should be passed to the parent view.

For example:

  root.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
  return false;
}
});

Documentation: https://developer.android.com/reference/android/view/View.OnTouchListener

Related