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

1

1 Answer 1

23

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

4
  • singleLine is deprecated, though
    – Andrew
    Jul 30, 2010 at 19:12
  • 2
    What would I do if I want to ellipsize a TextView with more then one line?
    – Janusz
    Jan 4, 2011 at 13:42
  • 6
    @Andrew Why would you think singleLine is deprecated? developer.android.com/reference/android/widget/…
    – Chloe
    Mar 4, 2013 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 4, 2013 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.