Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android enabling scrolling on edittext

Tags:

java

android

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 How to make edittext in Android scrollable? but it isnt working

like image 320
Janwel Avatar asked Jan 22 '26 07:01

Janwel


1 Answers

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>
like image 74
XepterX Avatar answered Jan 23 '26 20:01

XepterX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!