5

I have searched for the solution but it seems those are not working. Is it my case not applicable for changing the xml? How to fix the problem ? The scroll view work but the edittext not working. Thanks

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/share_bg" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:overScrollMode="never" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/photo_area"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/share_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/photo_area"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="@string/share_title"
                android:textColor="@android:color/white" />

            <EditText
                android:id="@+id/share_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/share_title"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/custom_textarea"
                android:gravity="top|left"
                android:lines="5"
                android:scrollbars="vertical"
                android:text="@string/default_msg" >

                <requestFocus />
            </EditText>

            <ImageView
                android:id="@+id/share_submit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/share_content"
                android:layout_centerHorizontal="true"
                android:src="@drawable/photo_taken_btn_submit" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

The id: share_content is the editText, Thanks

user782104
  • 12,011
  • 51
  • 154
  • 289

1 Answers1

18

You can perform this to make an edittext scrollable:

 EditText EtOne = (EditText) findViewById(R.id.comment1);
EtOne.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (v.getId() == R.id.comment1) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_UP:
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                        break;
                    }
                }
                return false;
            }
        });

See "Scrolling editbox inside scrollview"

Community
  • 1
  • 1
Ravinder Bhandari
  • 2,376
  • 19
  • 24
  • Could you clarify the purpose of MotionEvent.ACTION_MASK? – Vigneshwaran.m Dec 19 '14 at 06:31
  • Thanks, this helped me. I was able to shorten the entire if block to just `v.getParent().requestDisallowInterceptTouchEvent(! ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP));` though, it looks cleaner to me. –  Jan 30 '15 at 09:55