Android Question in code ListView property Change

sina39000

Member
Hello
A simple problem:
How can i change ListView TextSize property in run time?
B4X:
Sub Process_Globals
End Sub

Sub Globals
    Private Button1 As Button
    Private EditText1 As EditText
    Private ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    EditText1.Text = 20
    ListView1.SingleLineLayout.Label.TextSize = EditText1.Text
    ListView1.SingleLineLayout.ItemHeight = EditText1.Text*4
    For i = 0 To 10
        ListView1.AddSingleLine("Item No "&i)
    Next
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub ShowList
    ListView1.Clear
    ListView1.SingleLineLayout.Label.TextSize = EditText1.Text
    ListView1.SingleLineLayout.ItemHeight = EditText1.Text*4
    For i = 0 To 10
        ListView1.AddSingleLine("Item No "&i)
    Next
End Sub

Sub Button1_Click
    ShowList
End Sub

I want to change ListView Font Size By simply enter size value in EditText1 and press Button1 but it not works
 

Attachments

  • ListViewTest.zip
    9 KB · Views: 343

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are adding the items with AddTextItem then each item will be made of a single label. You need to get the label and set its text size:
B4X:
clv1.GetPanel(3).GetView(0).TextSize = 30 'change the text size of the 4th item

Tip: in B4J you will need to do an extra step:
B4X:
Dim lbl As Label = clv1.GetPanel(3).GetView(0)
lbl.TextSize = 30
CSSUtils.SetStyleProperty(lbl, "-fx-font-size", lbl.TextSize) 'required because the default text item label is based on the designer label and its font size is also set in the Style property.
 
Upvote 0
Top