Android Question in code ListView property Change

Discussion in 'Android Questions' started by sina39000, Jun 28, 2019.

  1. sina39000

    sina39000 Member

    Hello
    A simple problem:
    How can i change ListView TextSize property in run time?
    Code:
    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
     

    Attached Files:

  2. sina39000

    sina39000 Member

    thank you so much
    i found answer in this link
    is there another way to avoid from remove view and create again?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    In most cases it is a mistake to use ListView. Use xCustomListView instead. It is simpler to use and can be easily customized.
     
    sina39000 likes this.
  4. sina39000

    sina39000 Member

    thank you Erel,
    How can i change xCustomListView text size in run time?
     
  5. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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:
    Code:
    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.
     
    sina39000 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice