End the ellipse problem with TextViews

Andrew picture Andrew · Jul 30, 2010 · Viewed 9.9k times · Source

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

Answer

Romain Guy picture Romain Guy · Jul 30, 2010

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