Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText not wrapping its content

Tags:

android

I am trying to create an EditText which toggles its state between read only and write mode. My XML is as below:

<EditText xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textArea" 
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" 
 android:lines="4"
 android:inputType="textMultiLine">
</EditText>

In my code i do the following :

textArea = (EditText) convertView.findViewById(com.pravaa.mobile.R.id.textArea);
  //isEditable decides if the EditText is editable or not
 if(!isEditable){
        textArea.setInputType(InputType.TYPE_NULL);
  }
  //the view is added to a linear layout. 
  addView(textArea);

My issue is that the text does not get wrapped. Am i missing out on something? Kindly help me with this. I have also attached an image of my output.

EditText does not exapnd in height

The text does not wrap

The text set in the view is "12345678901234567 90123456789012345678901234567890 Nationwide Campaign New"

like image 940
S.A.Norton Stanley Avatar asked Apr 21 '11 10:04

S.A.Norton Stanley


People also ask

Is EditText deprecated?

New! Save questions or answers and organize your favorite content. Learn more.

What is TextInputLayout in android?

TextInputLayout is a view container that is used to add more features to an EditText. It acts as a wrapper for EditText and has some features like: Floating hint. Animation that can be disabled or enabled. Error labels that display error messages when an error occurs.

How do I edit EditText Uneditable?

In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.

What is EditText control?

A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.


2 Answers

I was able to solve this issue by removing

 android:inputType="textMultiLine"

To achieve the non-editable feature I used

 setFocusable(false);
like image 88
S.A.Norton Stanley Avatar answered Oct 13 '22 20:10

S.A.Norton Stanley


I guess that by calling this ...

textArea.setInputType(InputType.TYPE_NULL);

you override the flag InputType.TYPE_TEXT_FLAG_MULTI_LINE. Try calling this instead...

textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
like image 25
taymless Avatar answered Oct 13 '22 21:10

taymless