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

Discussion in 'Android Questions' started by Roger Daley, Jun 25, 2015.

  1. Roger Daley

    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?

    Code:
    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, 050%y100%x50%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
     
  2. DonManfred

    DonManfred Expert Licensed 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
     
  3. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks DonManfred,

    Not immediately obvious, but I think I have it now.

    [InsertAtTextItem is the key]


    Regards Roger
     
  4. DonManfred

    DonManfred Expert Licensed User

    yes

    Code:
    '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, 
    5dip2dip, sv.Width - 5dip20dip)
        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
     
  5. Roger Daley

    Roger Daley Well-Known Member Licensed User

    One last query.

    What is the "Value" in the First/last lines of code above?

    Public Sub InsertAtTextItem(Index As Int, Text AsString, Value As Object)
    InsertAt(Index, pnl, lbl.Height + 2dip, Value)

    Roger
     
  6. DonManfred

    DonManfred Expert Licensed User

    Code:
    clv1.AddTextItem("Shear" & CRLF & "Max Shear = " & sheardesign , "a")
    ->
     
    Roger Daley likes this.
  7. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Return Value when item clicked! Got it.

    Thanks DonManfred [ ... and mangojack whose reply disappeared. ???]

    Regards Roger
     
    Last edited: Jun 25, 2015
  8. Roger Daley

    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
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You will need to modify the source code, pass the color to the InsertAtTextItem method and set the panel background color.
     
  10. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Yes Erel, it is how to pass the text colour for each item that has me stuck .

    Roger
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Same way. Add the two parameters to this sub.
     
  12. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Sorry, you've lost me. I will stick with ListView and forgo the colour change.

    Roger
     
Loading...