13

I have a bottom sheet dialog and exists EditText in layout. EditText is multiline, max lines is 3. I put :

commentET.setMovementMethod(new ScrollingMovementMethod());
commentET.setScroller(new Scroller(bottomSheetBlock.getContext()));
commentET.setVerticalScrollBarEnabled(true);

but when user will begin scrolling text of EditText vertically BottomSheetBehavior intercept event and EditText will not scroll vertically.

enter image description here

Anybody know how to solve this problem?

SBotirov
  • 13,872
  • 7
  • 59
  • 81
  • How did you create this dialog using alertdialog or popupwindow? – Jai Oct 24 '16 at 12:53
  • no, this is simple my custom layout with BottomSheetBehavior – SBotirov Oct 24 '16 at 13:12
  • In that case you have to pass touch event to your front dialog sheet using onDispatchTouchEvent and you could resolve this issue! You are getting such issue because you have something with your BottomSheet which is getting focused – Jai Oct 24 '16 at 13:19
  • And if you don't want this touchevent stuff, you could open it inside alertdialog or popupwindow would be better option – Jai Oct 24 '16 at 13:27

3 Answers3

20

Here is an easy way to do it.

yourEditTextInsideBottomSheet.setOnTouchListener(new OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
        v.getParent().requestDisallowInterceptTouchEvent(true);
        switch (event.getAction() & MotionEvent.ACTION_MASK){
        case MotionEvent.ACTION_UP:
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }
        return false;
   }
});
HenBoy331
  • 1,915
  • 16
  • 20
7

For those who are interested in Kotlin solution. Here it is

editText.setOnTouchListener { v, event ->
    v.parent.requestDisallowInterceptTouchEvent(true)
    when (event.action and MotionEvent.ACTION_MASK) {
        MotionEvent.ACTION_UP -> 
                      v.parent.requestDisallowInterceptTouchEvent(false)
    }
    false
}
Muhammad Umair Shafique
  • 2,475
  • 1
  • 30
  • 39
1

I solve this issues with following way:

  1. I created custom work around bottom sheet behavior extends native android BottomSheetBehavior:

    public class WABottomSheetBehavior<V extends View> extends BottomSheetBehavior<V> {
    private boolean mAllowUserDragging = true;
    
    public WABottomSheetBehavior() {
        super();
    }
    
    public WABottomSheetBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public void setAllowUserDragging(boolean allowUserDragging) {
        mAllowUserDragging = allowUserDragging;
    }
    
    @Override
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
        if (!mAllowUserDragging) {
            return false;
        }
        return super.onInterceptTouchEvent(parent, child, event);
    }
    }
    
  2. then set touch event of EditText and when user touching area of EditText I will be disable handling event by parent with calling method setAllowUserDragging :

    commentET.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (v.getId() == R.id.commentET) {
            botSheetBehavior.setAllowUserDragging(false);
            return false;
        }
        return true;
    }
    });
    
MinnuKaAnae
  • 1,646
  • 3
  • 23
  • 35
SBotirov
  • 13,872
  • 7
  • 59
  • 81