Optimal display the contents of a label

AlpVir

Well-Known Member
Licensed User
Longtime User
The attached image shows the desired end result of how you would like to submit a series of items that are part of a CustomListView.
Each item consists of 3 labels: the first is normal, the second is with bold font and the third contains a text very very long.
I would like this text to be truncated to the third row and to the right point (between 2 words, or at a punctuation mark) and was followed by three or four dots blacks ("....")
Photoshopped image is in the red because I wanted to highlight the salient point of this problem.
I made some attempt that uses the Canvas
B4X:
w=Canvas1.MeasureStringWidth(str,Typeface.DEFAULT, 11)
but it is very slow (the items can also be numerous, 200-300) and in any case takes into account only the first line of the 3 that make up the label No. 3
I also tried with
B4X:
StringUtils.MeasureMultilineTextHeight (lbl, text)
but I did not get an acceptable result.
Thanks in advance
 

Attachments

  • trePuntini copia.jpg
    trePuntini copia.jpg
    120 KB · Views: 253

AlpVir

Well-Known Member
Licensed User
Longtime User
Thanks, however, the result of SetMaxLines is strange.
In the first image I set SetMaxLines 2 and the third row disappears.
In the second image I set SetMaxLines to 3, and the third line appears but the dots are on the second !!!
Despite numerous attempts have never been able to put the dots on the third line.
Thanks again but what is wrong?
The code is

B4X:
Sub SetEllipsize(TextView As Label, Mode As String)
  Dim r As Reflector
  r.Target = TextView
  'r.RunMethod2("setLines", 3, "java.lang.int")
  r.RunMethod2("setMaxLines",3,"java.lang.int")  ' or 2
  'r.RunMethod2("setSingleLine", False, "java.lang.boolean")
  'r.RunMethod2("setHorizontallyScrolling", False, "java.lang.boolean")
  r.RunMethod2("setEllipsize", Mode, "android.text.TextUtils$TruncateAt")
End Sub
 

Attachments

  • SetMaxLines2.png
    SetMaxLines2.png
    43.4 KB · Views: 240
  • SetMaxLines3.png
    SetMaxLines3.png
    61.1 KB · Views: 270
Upvote 0
Top