5

I have a TextView that is a single line. How can I add ellipses (...) if the text is too long?

Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556

2 Answers2

6

In your XML-file you can use: android:ellipsize="end".

In your .java code you can use: yourTextView.setEllipsize(TextUtils.TruncateAt.valueOf("END"));.

Remember to use it when you want ellipses if the text is reaching its parent's width.

Wroclai
  • 26,835
  • 7
  • 76
  • 67
2

Be aware of some issues by using the function: Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?

however, its still the most robust way to do it.

Community
  • 1
  • 1
OneWorld
  • 17,512
  • 21
  • 86
  • 136