Skip to content Skip to sidebar Skip to footer

Android: Make Multiline Edittext Scrollable, Disable In Vertical Scroll View

I am developing an application in which i am struct at a point. As according to my application requirement i created horizontal scrollview in xml and then vertical scrollview in .j

Solution 1:

You can do one thing.

Just make edit text focusable false. And apply on touch listener.

So user is not able to edit text and it will scroll as:

EditTexteditText=newEditText(this);
editText.setId(1);
editText.setLayoutParams(newTableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,0f));
editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setGravity(Gravity.TOP|Gravity.LEFT);
editText.setHint("Comment");
editText.setSingleLine(false);
editText.setLines(5);
editText.setMaxLines(5);
editText.setText(CommentFromDB);
editTextRemark.setFocusable(false);

Apply onTouchListner as:

editTextRemark.setOnTouchListener(touchListener);

and

OnTouchListenertouchListener=newView.OnTouchListener(){
    publicbooleanonTouch(final View v, final MotionEvent motionEvent){
        if(v.getId() == 1){
            v.getParent().requestDisallowInterceptTouchEvent(true);
            switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
                case MotionEvent.ACTION_UP:
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
        }
        returnfalse;
    }
};

Hope this answer will help you.

Solution 2:

EditText editText = findViewById(R.id.editText);
editText.setOnTouchListener(new OnTouchListener() {
               public boolean onTouch(View view, MotionEvent event) {
                    // TODO Auto-generated method stubif (view.getId() ==R.id.common_remark) {
                        view.getParent().requestDisallowInterceptTouchEvent(true);
                        switch (event.getAction()&MotionEvent.ACTION_MASK){
                        case MotionEvent.ACTION_UP:
                            view.getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                        }
                    }
                    returnfalse;
                }
        });

And in xml add this line in EditText:

android:scrollbars = "vertical"

Solution 3:

add to EditText

 android:inputType="textMultiLine"

Solution 4:

in kotlin use this

editText.setOnTouchListener { v, event ->
    v.parent.requestDisallowInterceptTouchEvent(true)
    when (event.action and MotionEvent.ACTION_MASK) {
        MotionEvent.ACTION_UP ->  v.parent.requestDisallowInterceptTouchEvent(false)
    }
    false
}

Post a Comment for "Android: Make Multiline Edittext Scrollable, Disable In Vertical Scroll View"