views:

754

answers:

4

I have been trying to get my EditText box to word wrap, but can't seem to do it.

I have deal with much more complicated issues while developing Android applications, and this seems like it should be a straight-forward process.

However, the issue remains, and I have a large text box that is only allowing me to enter text on one line, continuing straight across, scrolling horizontally as I enter text.

Here is the XML code for the EditText object from my layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/myWidget48"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
 <ScrollView
    android:id="@+id/myScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    >
    <LinearLayout
        android:id="@+id/widget37"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
    >

<EditText
        android:id="@+id/txtNotes"
        android:layout_width="300px"
        android:layout_height="120px"
        android:scrollbars="vertical"
        android:textSize="18sp"
        android:gravity="left"
        android:layout_marginTop="10dip"
        android:inputType="textCapSentences"
        >
    </EditText>
</LinearLayout>
</ScrollView>
</LinearLayout>
A: 

Ok i figured it out, you must set android:scrollHorizontally="false" in your xml. I'm pretty sure this should work.

Enigma Development
A: 

I tried it with the following XML layout settings, and still no luck.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/myWidget48"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
 <ScrollView
    android:id="@+id/myScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    >
    <LinearLayout
        android:id="@+id/widget37"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
    >

<EditText
        android:id="@+id/txtAcctRegNotes"
        android:layout_width="fill_parent"
        android:layout_height="120px"
        android:scrollbars="vertical"
        android:textSize="18sp"
        android:gravity="left"
        android:layout_marginTop="10dip"
        android:nextFocusUp="@+id/txtChkAmount"
        android:nextFocusLeft="@+id/txtChkAmount"
        android:nextFocusDown="@+id/btnChkSave"
        android:nextFocusRight="@+id/btnChkSave"
        android:inputType="textCapSentences"
        android:singleLine="false"
        android:scrollHorizontally="false"
        >
    </EditText>
</LinearLayout>
</ScrollView>
</LinearLayout>
Bryan
A: 

I figured it out. The line,

android:inputType="textCapSentences"

was the issue. Adding this line to an EditText object will make the object be a single line EditText, and will not let words wrap, or allow a user to press 'Enter' to insert a line feed or carriage return in the EditText.

Bryan
+1  A: 

Beside finding the source of the issue, I found the solution. If 'android:inputType' is used, then 'textMultiLine' must be used to enable multiLine support. Also, using 'inputType' supercedes the code 'android:singleLine="false"'. If using 'inputType', then, to reiterate, 'textMultiLine' must be used or the EditText object will only consist of one line, without word-wrapping.

Example XML code:

<EditText android:id ="@+id/edtInput"
android:layout_width ="0dip" 
android:layout_height ="wrap_content" 
android:layout_weight ="1" 
android:inputType="textCapSentences|textMultiLine"
android:maxLines ="4" 
android:maxLength ="2000" 
android:hint ="@string/compose_hint"/>
Bryan