Hi All!
I need dynamically update ListView ItemHeight which depends from SecondLabel height (lines count), but not all items receive the new size.
Screenshots and demo project is attached.
Where troubles?
:sign0085:
Code:
I need dynamically update ListView ItemHeight which depends from SecondLabel height (lines count), but not all items receive the new size.
Screenshots and demo project is attached.
Where troubles?
:sign0085:
Code:
B4X:
Sub Process_Globals
End Sub
Sub Globals
Dim EditText1 As EditText
Dim LV As ListView
Dim Button1 As Button
Dim Label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim Count, i As Int
LV.Clear
SetItemHeight(EditText1.Text)
For i = 0 To 50
LV.AddTwoLines("Header " & i, SetLines(EditText1.Text))
Next
End Sub
Sub SetLines(Count As Int) As String
Dim i As Int
Dim SB As StringBuilder
SB.Initialize
For i = 1 To Count
If i <> Count Then SB.Append("Line " & i & CRLF) Else SB.Append("Line " & i)
Next
Return SB.ToString
End Sub
Sub SetItemHeight(Lines As Int)
Dim C As Canvas
C.Initialize(LV)
LV.TwoLinesLayout.Label.Height = 2 * C.MeasureStringHeight("W", Typeface.DEFAULT, LV.TwoLinesLayout.Label.TextSize)
LV.TwoLinesLayout.SecondLabel.Height = 2 * Lines * C.MeasureStringHeight("W", Typeface.DEFAULT, LV.TwoLinesLayout.SecondLabel.TextSize)
LV.TwoLinesLayout.ItemHeight = (LV.TwoLinesLayout.Label.Height + LV.TwoLinesLayout.SecondLabel.Height)
Label1.Text = "Items height: " & LV.TwoLinesLayout.ItemHeight
End Sub
Attachments
Last edited: