Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Multi line text EditText inside BottomSheetDialog

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?

like image 724
SBotirov Avatar asked Oct 24 '16 12:10

SBotirov


People also ask

How do I allow multiline input using Edittext?

Just add this android:inputType="textMultiLine" in XML file on relevant field. Save this answer.

How to use bottomSheet dialog in android?

February 19, 2021. Bottom Sheet dialogs seem to be replacing regular Android dialogs and menus. The Bottom Sheet is a component that slides up from the bottom of the screen to showcase additional content in your application. A Bottom Sheet dialog is like a message box triggered by the user's actions.

How do you use bottomSheetFragment?

BottomSheetDialogFragment bottomSheetFragment = new YourBottomSheetFragmentClass(); bottomSheetFragment. show(getFragmentManager(), bottomSheetFragment. getTag()); Or if you want to pass some data to BottomSheetDialogFragment use below code, with newInstance you can send and retrieve data.


2 Answers

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
}
like image 83
Muhammad Umair Shafique Avatar answered Oct 18 '22 18:10

Muhammad Umair Shafique


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;
   }
});
like image 19
HenBoy331 Avatar answered Oct 18 '22 20:10

HenBoy331