Android EditText unlimited text length

2019-07-26 07:56发布

问题:

is there a device specific limitation (other then total free memory size) to text length or line count in scrollable multiline EditText when android:maxLength and android:maxLines is NOT set? I have an EditText:

<EditText
  android:editable="false"
  android:id="@+id/sip_log_log"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_weight = "1"
  android:text=""
  android:gravity = "top"
  android:textColor="#00FF00"
  android:background="#000000"
  android:scrollbars="vertical"
  android:focusable="true"
  />

and when I call

mEditText.setText("some very very loooong string....");

only the first part of the text is shown. The issue is device specific. Everything works well on HTC Sensation or in emulator, but Samsung Galaxy S 2 does never show more than about 20 pages of the text. Can I fix it in some way? Or is there an alternative way to show extremely long texts (SIP log in our SIP client) in some other standard view with scroll bar?

Thanks to all replies.

回答1:

Adding android:maxLength="99999999" to your layout file fixes this!



回答2:

I have tested WebView which works well even with long texts but still I would like to know why EditText on Samsung Galaxy does not work correctly.



回答3:

I had this same problem, and setting android:maxLength="999999 in the XML didn't fix this. But programmatically setting the length filter worked, like this:

    EditText mPrimaryPhoneField = (EditText) findViewById(R.id.primary_phone);
    InputFilter[] phoneFilterArray = new InputFilter[1];
    //This needs to be a large number to fix a bug on Samsung Galaxy tablet where it would have a default limitation on numeric fields if you had no length filter at all.
    phoneFilterArray[0] = new InputFilter.LengthFilter(100);
    mPrimaryPhoneField.setFilters(phoneFilterArray);