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

Roger Daley

Well-Known Member
Licensed User
Longtime 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?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    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)
    Next
End Sub

Thanks in advance.

Regards Roger
 

DonManfred

Expert
Licensed User
Longtime User
See the content of the sub AddTextItem to find out what happens here. There you should find the right infos to add color, size, whatever
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
InsertAtTextItem is the key
yes

B4X:
'Inserts a text item at the specified index.
Public Sub InsertAtTextItem(Index As Int, Text As String, Value As Object)
    Dim pnl As Panel
    pnl.Initialize("")
    Dim lbl As Label
    lbl.Initialize("")
    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
    Else
        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
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0
Top