3

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

Community
  • 1
  • 1
Janwel
  • 300
  • 1
  • 5
  • 17

4 Answers4

3

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>
XepterX
  • 1,017
  • 6
  • 16
  • can I use that even if I have a Scrollview for all my tools? and how about my background can I designate it on my scrollview? – Janwel Aug 30 '12 at 09:17
  • you already had a scrollview within the layout? if yes then you can't use another scrollview but there is a workaround for that. yes, you can use the background attribute. – XepterX Aug 30 '12 at 09:20
  • you could use this attribute for textview android:scrollbars="vertical". you can discard scrollview then – XepterX Aug 30 '12 at 09:33
  • just use textview, you don't need the scrollview that i suggested – XepterX Aug 30 '12 at 09:36
  • No sir it isnt scrolling Please se my code above Ill post my whole xml file – Janwel Aug 30 '12 at 09:46
0

Instead of specifying the Max lines, reduce your EditTextHeight.

For Eg :

Layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/etConditionBody"
    android:layout_width="fill_parent"
    android:layout_height="300dp" >
</EditText>

</LinearLayout>

Code :

etConditionBody = (EditText) findViewById(R.id.etConditionBody);
    etConditionBody.setScroller(new Scroller(getBaseContext()));
    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");
Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
0

As you put etConditionBody.setMaxLines(8); it will always show you only 8 lines as it override the layout_height parameter. remove the setMaxLines and minimize the layout_height. It will scroll then.

Neha
  • 414
  • 1
  • 4
  • 14
0

update your corresponding java file with following code

 EditText etText = (EditText) findViewById(R.id.etText);       
 dwEdit.setOnTouchListener(new OnTouchListener() {
       public boolean onTouch(View view, MotionEvent event) {

            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;
        }
    });