6

I'm using an EditText of some predefined size, however when a user enters more text then fits in the text box, they aren't able to scroll the text with touch. Scrolling does work with a trackball.

What can I do to fix this?

pensono
  • 216
  • 5
  • 17
Bytecode
  • 6,171
  • 15
  • 48
  • 99
  • 1
    possible duplicate of [Making TextView Scrollable in Android](http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android) – Octavian A. Damiean May 25 '11 at 11:59

4 Answers4

26

If you would like the text to scroll horizontally, define in your EditText XML tag:

android:scrollHorizontally="true"

If you would like a vertical scroll, define in your EditText XML tag:

android:scrollbars = "vertical"

Hope this helped.

Vinay
  • 5,510
  • 5
  • 34
  • 52
  • Let me know if I'm misunderstanding something. – Vinay May 25 '11 at 12:04
  • when i am set the max line more than one then it's not working ! – Prince Dholakiya Jul 18 '18 at 11:52
  • Hmm @yesterday this answer was given quite a long time ago. I no longer do Android development, so I'm not really in a place where I can help out. If anyone has any suggestions to his comment - happy to update my answer or delete if there's a better one! – Vinay Jul 19 '18 at 18:51
15

make the changes like the following to get scroller in your EditText

questionEntry.setScroller(new Scroller(myContext)); 
questionEntry.setMaxLines(1); 
questionEntry.setVerticalScrollBarEnabled(true); 
questionEntry.setMovementMethod(new ScrollingMovementMethod()); 

How to make edittext in Android scrollable?

Donot forget to vote if you feel my response is helpful for you

Thanks Deepak

Community
  • 1
  • 1
Sunil Kumar Sahoo
  • 49,865
  • 50
  • 172
  • 240
9

In java

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

In xml

<EditText
android:id="@+id/DwEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="10"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical" 
android:overScrollMode="always"
android:inputType="textCapSentences">
</EditText> 
Amsheer
  • 6,666
  • 8
  • 39
  • 74
0

A simple way to do scroll-able text in edittext if parent is NestedScrollView or ScrollView

XML code

android:gravity="top"
android:inputType="text|textMultiLine"
android:lines="5"

Use below code for Kotlin

    editText.setOnTouchListener { v, event ->
        if (v.id == R.id.editText) {
            v.parent.requestDisallowInterceptTouchEvent(true)
            when (event.action and MotionEvent.ACTION_MASK) {
                MotionEvent.ACTION_UP -> v.parent.requestDisallowInterceptTouchEvent(false)
            }
        }
        false
    }
Pratik Dodiya
  • 559
  • 4
  • 8