开发者

EditText not wrapping its content

开发者 https://www.devze.com 2023-02-28 01:01 出处:网络
I am trying to create an EditText which toggles its state between read only and write mode. My XML is as below:

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"
 an开发者_StackOverflow中文版droid: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 not wrapping its content

EditText not wrapping its content

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


I was able to solve this issue by removing

 android:inputType="textMultiLine"

To achieve the non-editable feature I used

 setFocusable(false);


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


This line will make the text multi-line and will wrap the text

textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);

You'd probably also want to call setLines(n) to set the height of the textArea.


Try to replace:

editText.setInputType(InputType.TYPE_NULL);

with:

editText.setRawInputType(InputType.TYPE_NULL);


I would say that by using textArea.setInputType(InputType.TYPE_NULL); you remove the textMultiLine from your xml.


Just set textMultiLine isn't enough. Try this:

textArea.setHorizontallyScrolling(false);
textArea.setEllipsize(null);
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);


What me helped was:

edtText.setInputType(InputType.TYPE_NULL);
edtText.setSingleLine(false);

It seems that the setSingleline Attribute in the XML file is ignored.

0

精彩评论

暂无评论...
验证码 换一张
取 消