I am loading 5 textparts in 5 txtviews. Soms parts are 1 sentence soms are 3 sentences. I would like the textviews to ‘expand’ according to the content.
How would you tackle this.
Do you need the text to be editable? If not then use CustomListView.AddTextItem.
This is the code from CustomListView that sets the label height based on the text:
B4X:
Private Sub CreateLabel(txt As Object) As B4XView
Dim lbl As Label
lbl.Initialize("")
lbl.TextAlignment = DesignerLabel.TextAlignment
lbl.Font = DesignerLabel.Font
lbl.Multiline = True
lbl.TextColor = DefaultTextColor
If txt Is AttributedString Then
lbl.AttributedText = txt
Else
lbl.Text = txt
End If
lbl.Width = sv.ScrollViewContentWidth - 10dip
lbl.SizeToFit
Return lbl
End Sub
You can use similar code to create a label with the correct height and then set the TextView height based on the label's height.