Android Question How to set colours and text size in customlistview???

Roger Daley

Well-Known Member
Licensed User
Hi All

In Erels example of customlistview the following code is used to create two lists. The first list uses the "addtextitem" this is all I need but how do I set the panel colour, text colour and text size?

Sub Activity_Create(FirstTime As Boolean)
    clv1.AddTextItem("Aaaa", "a")
    clv1.AddTextItem("Aaaa" & CRLF & "Bbbb", "b")
    clv1.AddTextItem("Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc", "c")
    clv1.AddTextItem("Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" , "d")
    clv1.AddTextItem("Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" & CRLF & "Eeee", "e")
    'Second list is created programmatically.
    'Create 20 items made of a label, button and checkbox.
    clv3.Initialize(Me, "clv3")
    Activity.AddView(clv3.AsView, 0, 50%y, 100%x, 50%y)
    For i = 1 To 10
        clv3.Add(CreateListItem("Item #" & i, clv3.AsView.Width, 50dip), 50dip, "Item #" & i)
End Sub
Thanks in advance.

Regards Roger


Licensed User
InsertAtTextItem is the key

'Inserts a text item at the specified index.
Public Sub InsertAtTextItem(Index As Int, Text As String, Value As Object)
    Dim pnl As Panel
    Dim lbl As Label
    lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.LEFT)
    pnl.AddView(lbl, 5dip, 2dip, sv.Width - 5dip, 20dip)
    lbl.Text = Text
    lbl.TextSize = DefaultTextSize
    lbl.TextColor = DefaultTextColor
    ' You can define your Textsize and Textcolor here
    If DefaultTextBackground <> Null Then
        pnl.Background = DefaultTextBackground
        pnl.Color = DefaultTextBackgroundColor
    End If
    ' You can set any other color to pnl if you want...
    Dim minHeight As Int
    minHeight = su.MeasureMultilineTextHeight(lbl, Text)
    lbl.Height = Max(50dip, minHeight)
    InsertAt(Index, pnl, lbl.Height + 2dip, Value)
End Sub

Roger Daley

Well-Known Member
Licensed User
Still stuck on how to change text colour on individual items programatically.

The text colour for each item is determined in the Main module, the text colour is set in "InsertAtTextItem" in the CustomListView module.
The text colour is a label "FNumLabel1.TextColor" but if this used in the CustomListView module it is an Undeclared Variable.

Any clues?

Regards Roger