jburn2712
jburn2712

Reputation: 167

When EditText with pre-filled text becomes editable, all text moves to one single line

I have an EditText inside of a ScrollView which is pre-filled with a dynamic amount of text. It could be one line or 50 or more. At this point, the EditText is uneditable and the text is shown just fine. However, when I press a button to make the edit text editable, the entire contents of the EditText are thrown into one very long, horizontally scrolling line.

You can see exactly what I'm talking about here: https://zippy.gfycat.com/GenerousBigHerring.webm

How can I prevent this from happening? I've been screwing around with this for a while now. I've tried setting lines and maxLines, etc, but I can't figure it out.

Edit:

This is my current ScrollView/EditText:

<ScrollView
    android:id="@+id/result_text_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/result_title_text"
    android:layout_above="@+id/result_bottom_sheet"
    android:layout_marginTop="20dp"
    android:padding="5dp">


    <EditText
        android:id="@+id/extracted_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:padding="15dp"
        tools:text="Hello, World"
        android:textColor="@color/black"
        android:textStyle="bold"
        android:textSize="@dimen/extracted_text_size"
        android:textIsSelectable="true"
        android:inputType="none"
    />



</ScrollView>

From code, here's what I'm doing to to enable/disable editing:

 @Override
public void enableTextEditing() {
    mExtractedText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    mExtractedText.setOnKeyListener(this);
}

@Override
public void disableTextEditing() {
    mExtractedText.setInputType(InputType.TYPE_NULL);
    mExtractedText.setOnKeyListener(null);
}


@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        //All this does is call the View methods to disable text editing
        //and close the keyboard.
        mPresenter.doneEditingButtonPressed();
        return true;
    }
    return false;
}

Upvotes: 2

Views: 75

Answers (1)

htafoya
htafoya

Reputation: 19273

Add android:lines , android:minLines and android:maxLines to your EditText view

Also change android: inputType = "textMultiline"

You can add android:scrollbars="vertical" to your EditText as well if you wish

Upvotes: 1

Related Questions