2

I am displaying a long (random) text in a TextView. I want to show 3 lines in this TextView and show dots (...) if there is more content. I know I can limit the lines of a TextView with minLines and maxLines, but I don't know where to add the dots in the string.

E.g. the TextView could/should look like

"This i random text
 this is a short one
 and more is here..."

"This one has a very
 loooooooooooooooong
 string so where ..."
MrHill
  • 1,271
  • 3
  • 12
  • 19

2 Answers2

2

You don't need to know where to add the dots, the TextView can do it for you. Checkout android:ellipsize=end. Note that the ellipsize's algorithm doesn't work reliably in older android versions. There might be discrepancies between the exact behavior between 2.3, 3 and 4+. For example I know that it will not show more than two lines in 2.3

dmon
  • 30,048
  • 8
  • 87
  • 96
  • See also: http://stackoverflow.com/questions/2160619/android-ellipsize-multiline-textview – dmon May 18 '13 at 23:10
0

You can create a simple algorithm that checks which word is displayed at X characters and after or before this word, you can add the dots.

MrByte
  • 1,083
  • 2
  • 11
  • 21
  • but i don't know which word is displayed at the last position of an TextView. A TextView shows e.g different amount of words according to the size of the mobile phone.. (small device shows e.g. 9 words, large device shows 14 words) – MrHill May 18 '13 at 22:49