7

I have an EditText on my layout. Below are the attributes I currently have:

<EditText
   android:id="@+id/entryIdea"
   android:layout_width="fill_parent"
   android:layout_height="225sp"
   android:gravity="top"
   android:background="@android:drawable/editbox_background"
   android:scrollbars="vertical"/>

However, I can see the scrollbar but can't scroll it with mouse/touch. I thought that it may works if I put the corresponding listener since it works on TextView. Apparently, it isn't.

EditText et = (EditText)findViewById(R.id.entryIdea);
et.setMovementMethod(new ScrollingMovementMethod());

Can you guys help me on this?

Thank you so much in advance. Sammy

Sammm
  • 501
  • 4
  • 9
  • 25
  • 3
    you need to go through your previous questions and mark the best answer as the correct one. – Cheryl Simon Nov 30 '10 at 22:50
  • It should be scollable once you have enough lines in the EditText so it needs to be scrolled. You don't need to add the listener to make it work. Have you tried to fill it in with many lines of text? – Juhani Nov 30 '10 at 22:51

7 Answers7

7

In your XML try setting the EditText height not in layout_height, but rather use android:lines attribute (btw, using sp is not usually a good practice when setting a size for anything except font size. Using dp/dip is more natural in this case).

Meanwhile set layout_height to wrap_content. Otherwise the XML you presented (with the changes I've mentioned) worked fine for me even without specifying movement method in the code.

And of course, the scroll bar will appear when the actual amount of lines of text in the EditText is larger than that, indicated in android:lines attribute.

Coryffaeus
  • 390
  • 5
  • 8
  • Just for the record, as Coryffaeus (nice nickname btw) pointed, the scrollbars will only show if you set the attribute `scrollbars` and you surpass the number of lines specified. in `lines`, however, it will always scroll even if you didn't set it. – Juan José Melero Gómez Feb 26 '16 at 14:35
  • the question explicitly asks why the scrollbar can't be moved with a mouse or touch. It's not an issue about showing a scrollbar. I don't think anybody got the question right be the look of what they wrote. – Alberto M Aug 20 '21 at 15:34
4

refer this link

 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;
            }
        });
Community
  • 1
  • 1
Amsheer
  • 7,046
  • 8
  • 47
  • 81
3
editText1.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            if (view.getId() ==R.id.editText1) {
                view.getParent().requestDisallowInterceptTouchEvent(true);
                switch (event.getAction()&MotionEvent.ACTION_MASK){
                case MotionEvent.ACTION_UP:
                    view.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }
            }
            return false;
        }
    });
Robert
  • 5,278
  • 43
  • 65
  • 115
2

use this:

 android:maxLines="5"

attribute for your xml file. Then the scrollbars attribute will work.

Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
user2574723
  • 125
  • 10
1
editText1.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View view, MotionEvent event) {
        // TODO Auto-generated method stub
        if (view.getId() ==R.id.editText1) {
            view.getParent().requestDisallowInterceptTouchEvent(true);
            switch (event.getAction()&MotionEvent.ACTION_MASK){
            case MotionEvent.ACTION_UP:
                view.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
        }
        return false;
    }
});
Ghasem
  • 14,455
  • 21
  • 138
  • 171
1

in xml file use:

android:maxLines="5" android:scrollbars = "vertical"

and in .java file add

edt_text.setMovementMethod(new ScrollingMovementMethod());

-1

your xml file use:

android:maxLines="5"
slavoo
  • 5,798
  • 64
  • 37
  • 39
mahone
  • 1