Android: Make multiline edittext scrollable, disable in vertical scroll view

为君一笑 提交于 2019-11-30 23:14:39

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:

EditText editText = new EditText(this);
editText.setId(1);
editText.setLayoutParams(new TableLayout.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

OnTouchListener touchListener = new View.OnTouchListener(){
    public boolean onTouch(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;
            }
        }
        return false;
    }
};

Hope this answer will help you.

Rahul Patidar
EditText editText = findViewById(R.id.editText);
editText.setOnTouchListener(new OnTouchListener() {
               public boolean onTouch(View view, MotionEvent event) {
                    // TODO Auto-generated method stub
                    if (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;
                        }
                    }
                    return false;
                }
        });

And in xml add this line in EditText:

android:scrollbars = "vertical"
NBApps

add to EditText

 android:inputType="textMultiLine"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!