31

I am creating a dynamic layout that contains an edit text. I want to make this edit text scrollable.

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

Using this code I made my edit text scrollable. But the problem is when I am typing something. If it reaches the end of the edit text, it will stop typing my text and not automatically jump to the next line. If I press the enter key, it will jump. I want to make it automatic.

Smi
  • 12,505
  • 9
  • 53
  • 61
andro-girl
  • 7,416
  • 19
  • 65
  • 92

4 Answers4

36

I know this question has already got an answer, but if you wish to get the same result via XML, change

android:inputType="text"

to

android:inputType="textMultiLine"

for a vertically scrollable EditText.

Advait S
  • 2,663
  • 25
  • 34
31
questionEntry.setScroller(new Scroller(myContext)); 
questionEntry.setMaxLines(1); 
questionEntry.setVerticalScrollBarEnabled(true); 
questionEntry.setMovementMethod(new ScrollingMovementMethod()); 

i made some changes in my previous code.
above posted is my new code.

it s working...thanks for all

star angel
  • 510
  • 2
  • 7
  • 13
andro-girl
  • 7,416
  • 19
  • 65
  • 92
  • 2
    I don't think the setScroller() call is necessary - just the call to setMovementMethod(). – greg7gkb Mar 15 '12 at 22:05
  • 2
    This doesn't work for EditTexts with setKeyListener(null), or at all. – Don Larynx May 17 '15 at 20:27
  • 1
    Unfortunately this did not work for me setting these methods programmatically. I also tried nesting the EditText view in a NestedScrollView widget without success. – Adam Hurwitz Jun 20 '16 at 23:42
23

Try this, Hope it Helps

questionEntry.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (v.getId() == R.id.inputFormComments) {
            v.getParent().requestDisallowInterceptTouchEvent(true);
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_UP:
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
            }
        }
        return false;
    }
});
Tunaki
  • 116,530
  • 39
  • 281
  • 370
Deepak Ganachari
  • 325
  • 3
  • 11
0

Just let it know that it should act that way by:

android:isScrollContainer="true"
straya
  • 4,814
  • 1
  • 25
  • 33