ScrollBar doesnt work in EditText

166 views Asked by At

Hope all of you doing well.

My Problem is:

I have xml code like following:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_left_margin"
        android:layout_marginRight="@dimen/activity_right_margin"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_bottom_padding"
        android:paddingTop="@dimen/activity_top_padding" >

        <EditText
            android:id="@+id/custDetailsNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/name_cust_all_add"
            android:inputType="textPersonName"
            android:textSize="@dimen/common_fontsize" />

        <EditText
            android:id="@+id/custDetailsDescEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:hint="@string/description_add_all_cust"
            android:inputType="textMultiLine"
            android:lines="5"
            android:minLines="3"
            android:gravity="top|left"
            android:scrollbars="vertical"
            android:scrollbarStyle="insideInset"
            android:overScrollMode="always"
            android:fadeScrollbars="false"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:textSize="@dimen/common_fontsize" />
    </LinearLayout>

</ScrollView>

In that i have two EditText in </ScrollView>, Second <EditText/> does not scrolling inner side. Problem is Full View is scrolled while i am scrolling but i want to also scroll vertically in second EditText when user enter more than 5 lines. In that ScrollBar is displaying but not scrolling.

How can i solve this.

Your Help would be appreciated.

2

There are 2 answers

0
Aravin On

Try something like this in your code

ScrollView scroller = new ScrollView(this);
EditText et=(EditText)findViewById(R.id.yourEdittext);
scroller.addView(et);
1
Mandar Kakade On

This code should work.....

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.parentScrollView).setOnTouchListener(parentListener);

    findViewById(R.id.custDetailsDescEditText).setOnTouchListener(childListener);

}

OnTouchListener parentListener = new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        findViewById(R.id.custDetailsDescEditText).getParent()
                .requestDisallowInterceptTouchEvent(false);
        return false;
    }
};

OnTouchListener childListener = new View.OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
};