0

Is there a standard way to do this? My popup window has maxsize and I would like to cut the string if it is too long. Currently I'm doing

   if(txt.length()>320)
        {
            txt = txt.substring(0,320)+"...";
        }

but this seems crude and doesn't work sometimes because of paragraphs.

Raghavendra
  • 2,305
  • 25
  • 30
kluki
  • 59
  • 11
  • What exactly you want to achieve with the text to be shown – Manishika Oct 13 '16 at 12:06
  • There is no standard way. You don't get feedback about how much data is actually displayable inside the screen. – f1sh Oct 13 '16 at 12:10
  • to give a quick overview. No feedback huh . ok . Is there a good way to calculate how much string would fit ín the popup ? because the max size changes with the screensize. – kluki Oct 13 '16 at 12:19
  • 1
    http://stackoverflow.com/questions/8499698/trim-a-string-based-on-the-string-length. Check this answer. Might be helpful to use `Math.min` – Zozinski Oct 13 '16 at 12:54

1 Answers1

3

You can define below property to textview.

android:ellipsize="end"

vanDer
  • 116
  • 5