7

Whoa SDK, whoa...

So I'm attempting to add an ellipse to the end of my TextView (single line) before it runs off screen. I've read that ellipses are broke (developing for 2.1)? After Google searching, everyone seems to suggest setting inputType to text and maxLines to 1 and you will get an ellipse.

There are two problems with this: 1) The text runs off the screen, but doesn't ellipse. I can tell the text is running off the screen because only a half of a character is showing at the edge of the screen, but it's not printing "..." instead. 2) When I have inputType set on my TextView, clicking my list item no longer works! There is no highlighting when you click and the onListItemClick handler does not fire!

So...

What can I do here?

I would like to note that there are two ways one could ellipse. If the entire word does not fit on the screen, hide the entire word and add an ellipse. Or, just take off enough characters so an ellipse will fit. Ideally, the latter is what I want.

Thanks for your help

Andrew
  • 20,756
  • 32
  • 99
  • 177
  • I'm also dealing with this issue http://stackoverflow.com/questions/3769105/android-something-better-than-androidellipsizeend-to-add-to-truncated – OneWorld Sep 24 '10 at 17:54

1 Answers1

23

If you want to ellipsize, simply use android:singleLine="true", or android:ellipsize="end".

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • singleLine is deprecated, though – Andrew Jul 30 '10 at 19:12
  • 2
    What would I do if I want to ellipsize a TextView with more then one line? – Janusz Jan 04 '11 at 13:42
  • 6
    @Andrew Why would you think singleLine is deprecated? http://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine – Chloe Mar 04 '13 at 23:24
  • 1
    @Chloe the ADT code completion (in xml-layout editor) tells you so. Weird that nothing can be found about it in the docs... BTW: maxLines=1 + ellipsize=end gives you other results than singleLine=true – stoefln Nov 04 '13 at 14:20