Android Question Calculate the label height before ading to Custom list view

frenkipi

Member
Licensed User
Longtime User
Hello,

I am trying to calcule the height of my label, so that my clv will have a dynamic height. Other items heights will not be changed, but only my label for long text. Bellow is my examle:

B4X:
Dim MyAutosizedLabel As Label

MyAutosizedLabel.Initialize("")
MyAutosizedLabel.Visible = False
Activity.AddView(MyAutosizedLabel, 0,0,0,0)

MyAutosizedLabel.TextSize = 14
MyAutosizedLabel.Text = Text

Dim ItemHeight As Int = su.MeasureMultilineTextHeight(MyAutosizedLabel, MyAutosizedLabel.Text)

Log(ItemHeight)
MyAutosizedLabel.RemoveView

Dim k As Int
k=ItemHeight+340

   clv2.Add(CreateListItem(title, text, username, added, clv2.AsView.Width, IntToDIP(k)), IntToDIP(k), id)

my ItemHeight value log is 0.
As you can see, I am adding new autosizedLabel so that I can measure the height, but for label will will be displaying, the text will be added here:

B4X:
Sub CreateListItem(Title As String, Text As String, Owner As String , Added As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")

    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
    Activity.AddView(p, 0, 0, Width, Height)

    p.LoadLayout("CellItem")
    p.RemoveView
    OwnerText.Text=Owner
    AddedText.Text=Added

    LabelLargeText.Text=Text

    TitleText.Text=Title
    TextText.Text=Text
    Return p
End Sub

Thanko you for your help.

Regards!
 
Top