Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling scrollbar in EditText Android

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

like image 682
Sammm Avatar asked Nov 30 '10 22:11

Sammm


3 Answers

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.

like image 84
Coryffaeus Avatar answered Sep 23 '22 21:09

Coryffaeus


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;
            }
        });
like image 45
Amsheer Avatar answered Sep 22 '22 21:09

Amsheer


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;
        }
    });
like image 32
Patel Miral Avatar answered Sep 21 '22 21:09

Patel Miral