Janwel Janwel - 26 days ago 12
Java Question

Android enabling scrolling on edittext

just a simple question here. I have a edittext inside a scrollview. Here is my code regarding edittext

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="899dp" >

<LinearLayout
android:id="@+id/LL1"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:orientation="vertical" >

<ImageView
android:id="@+id/ivMainPic"
android:layout_width="match_parent"
android:layout_height="320dp"
/>

</LinearLayout>

<TextView
android:id="@+id/tvDescription"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_below="@+id/LL1"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="@string/strDescription"
android:textSize="14dp"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"/>

<TextView
android:id="@+id/tvCondition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tvDescription"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dip"
android:text="@string/strCondition"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />



<Button
android:id="@+id/btnGetOffer"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_below="@+id/etConditionBody"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="@string/strGetOffer"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:background="@drawable/roundedcorner"
android:textStyle="bold" />

<TextView
android:id="@+id/etConditionBody"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@+id/tvCondition"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:gravity="top"
android:paddingBottom="20dip"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:paddingTop="20dip"
android:scrollbars="vertical"
android:background="@drawable/edittextborder"/>

</RelativeLayout>
</ScrollView>


Now what I am doing is making it scrollable and a not editable edittext because I am feching its text on my db.
I tried using this code

etConditionBody= (EditText) findViewById(R.id.etConditionBody);
etConditionBody.setScroller(new Scroller(getBaseContext()));
etConditionBody.setMaxLines(8);
etConditionBody.setVerticalScrollBarEnabled(true);
etConditionBody.setMovementMethod(new ScrollingMovementMethod());
etConditionBody.setText("wew \n wew2 \n wew3 \n wew4 \n wew \n wew2 \n wew3 \n wew4 \n wew \n wew2 \n wew3 \n wew4 \n wew3 \n wew4 \n wew \n wew2 \n wew3 \n taena");


but it is not scrolling, it just limit my lines to 8

i used that code based on this links
how to enable vertical scrollbar of an edittext programmatically
http://stackoverflow.com/questions/5831392/how-to-make-edittext-in-android-scrollable
but it isnt working

Answer

Use a TextView instead of an edittext for this. You can use a scrollview for for the scrolling Such as

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="300dp">

<TextView
    android:id="@+id/tvConditionBody"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
/>

</ScrollView>
Comments