How can i count the line number of a text?

cjguajardo

Member
Licensed User
Longtime User
Guys, i hope you that can help me with this.

I need to count the lines of a Label.
I'm trying to implement a chat room, so in every comment it is a panel with three labels (author, Text and date).
I'm trying to do a chat like whatsapp or facebook, so i need to calculate the lines number of the main text to determine the height of the object (main Label).

The app should work in the most of devices, so we know that there are many devices with different resolution, so my question is how can i do this?, how can i calculate the number of lines of a text with a given width, and an independent resolution.


Thanks in advance.

P.D: Sorry for my poor english.
 

thedesolatesoul

Expert
Licensed User
Longtime User
You can use String Utils.
I usually set the height of the label to -1 (wrap content) initially, then calculate the height, and then set the heights of the other labels/panels.
E.g:
B4X:
Activity.AddView(lbldetails, (100%x-actwidth)/2 + 18dip, secondtop, actwidth-22dip, -1)
Dim su As StringUtils 
lbldetails.Height = su.MeasureMultilineTextHeight(lbldetails,lbldetails.Text) + 4dip
 
Upvote 0
Top