Android Question Change a row in an xCustomListView

Brad Henderson

Member
Licensed User
Hello
I am trying to change the background color of an item in an xCustomListView. I've searched but can't find any method other than changing the whole view. I would like to have certain elements of the list highlighted. Also can I change the default height of all elements in the view?
Thanks
Brad
 

mangojack

Well-Known Member
Licensed User
depending when you want to color , and what item / view is to be colored ....

this code colors the first label on a row ...
B4X:
'click of a button or other child view ...
Sub Button1_Click
    Dim Index As Int = clv1.GetItemFromView(Sender)
    Dim pnl As B4XView = clv1.GetPanel(Index)
    pnl.GetView(0).Color = Colors.Red     'view(0) = 1st label on panel.. refer order in Designer ViewTree for Item/Row layout

    'Another option ...
    'Dim lbl As B4XView = pnl.GetView(0)
    'lbl.Color = Colors.Red


'On a Item/ Row click ...
Sub clv1_ItemClick(Index As Int, Value As Object)
    Dim pnl As B4XView = clv1.GetPanel(Index)
    '........... samo



When you say Default Elements height .. are you referring to Row / Item height ?
In the xCLV example it is set to 60dip .. but you can create a global variable RowHeight , set it to desired height then pass it when creating your list ...
B4X:
clv1.Add(CreateListItem("This Value", clv1.AsView.Width, RowHeight), "This Value")
You can adjust your Item layout to suit also ..
 
Last edited:

Brad Henderson

Member
Licensed User
Thanks mangojack
I have it working by using clv1.DefaultTextBackgroundColor= Colors.lightgray prior to adding the item then setting it back to white after adding.
With the height issue I am referring to the Row/Item height for all items in the clv, I am using AddTextItem so will have to look at CreateListItem and adding a panel.

Thanks again
Brad
 

kisoft

Well-Known Member
Licensed User
Hi
I'm doing it, for example.
B4X:
Sub Process_Globals
    Dim wsk As Int
End Sub

Sub CreateListItem(Width As Int, Height As Int) As Panel

    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("cus")
    
    Select wsk
        Case 0
            p.Color=Colors.ARGB(255,100,200,50)
        Case 1
            p.Color=Colors.ARGB(255,200,100,50)
        Case 2
            p.Color=Colors.ARGB(255,20,200,50)
        Case 3
            p.Color=Colors.ARGB(255,10,100,50)
        End Select
    Return p
    
End Sub
Changing the value of wsk, you change the color of the panel.
 
Top