开发者

How to get around the text limitations of a TextView element?

Apparently there seems to be a text length limit on the TextView element when used within a ListView. I have to admit I have not checked the actual limit that I am facing, but it is clear to me that 2k characters is no biggie, where 4k characters is simply not being displayed. And "not displayed" is not even right, as the screen seems to be scroll开发者_开发技巧able for the full length of the TextView (although all I get to see is whitespace).

My issue: I am displaying a ListView for an email message. All parts of the mail are in seperate TextView elements that get dropped into the ListView. When a lengthy message (somewhere above 2k characters) is put into a TextView, the TextView remains empty but does occupy space.

My question: What alternatives/options are there to make this problem go away? Eg Making the entire message displayable (even long ones).

Thanks to anyone in advance for assistance.


Is there any reason you have to use a ListView? It seems like you'd be better served with a LinearLayout or RelativeLayout inside a ScrollView, or maybe just put the body of the email inside a ScrollView if you want to keep the other TextViews on the screen.

If you want to stick with the ListView, you might consider using String#substring(int beginIndex, int endIndex) to ellipsize the body and show the full body in another Activity launched in the onListItemClick handler for the list view. You can use the android:ellipsize property in your XML layout (or TextView#setEllipsize in Java code) to limit the text to a single line, but that is probably not what you want.


you can set the singleLine property to true so that only the text visible in single line can be shown on listview or in addition set the maxline property to 1


Have you tried to set android:maxLength property for TextView element in xml
or
to set filter new InputFilter.LengthFilter(maxlength)?


I have found the reason for this quirk!
This is a BUG that exists in Android < 2.2 !

After dziobas pointed out that he filled 10k char strings on 2.2, I tried this out on a new emulator image.
I am still going to change my code in the end to not use the ListView and reimplement my own ListView like class as Brian suggested

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜