Listview color change?

boten

Active Member
Licensed User
Longtime User
Is it possible to change the colors of the labels in Listview, once they are set.

I don't mean different colors for different rows.
What I mean is for example:
listview is white with black labels.

Can I change the entire color scheme, e.g: listview will be color1, labels will be color2 ?

change between several color schemes.
 

boten

Active Member
Licensed User
Longtime User
I did, but only listview.color changed.
I save the color scheme on a file i read at create, but the changes go into effect ONLY after close and restart. Very strange.
Tried invalidating the view and even label & secondlabel but no change.
Also different behavior between android 2 and 4.
Gotta think of something else.
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
this is the code I use when color scheme is changed:
(assuming lview is the listview)
B4X:
lview.TwoLinesLayout.Label.Color=HueBack
lview.TwoLinesLayout.Label.TextColor=HueFore
lview.TwoLinesLayout.SecondLabel.Color=HueBack
lview.TwoLinesLayout.SecondLabel.TextColor=HueFore
lview.Invalidate
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a closer look at this.
Unfortunately it's not possible to change, directly in B4A, the colors of ListView Labels once they have been defined.
The only way I see to do it is to remove the ListView add and fill it again.
This routine does it.
B4X:
Sub ChangeListViewColors(LVColor As Int, L1Color As Int, L1TextColor As Int, L2Color As Int, L2TextColor As Int)
    Dim l, t, w, h As Int
    Dim ta As Object
    
    'get the current properties
    l = ltvTest.left
    t = ltvTest.Top
    w = ltvTest.Width
    h = ltvTest.Height
    ta = ltvTest.Tag
    
    'remove and add again the ListView
    ltvTest.RemoveView
    Dim ltvTest As ListView
    ltvTest.Initialize("ltvTest")
    Activity.AddView(ltvTest, l, t, w, h)
    ltvTest.Tag = ta
    
    'set the colors
    ltvTest.Color = LVColor
    ltvTest.TwoLinesLayout.Label.Color = L1Color
    ltvTest.TwoLinesLayout.Label.TextColor = L1TextColor
    ltvTest.TwoLinesLayout.SecondLabel.Color = L2Color
    ltvTest.TwoLinesLayout.SecondLabel.TextColor = L2TextColor
    FillListView    'routine that fills the ListView
End Sub
Perhaps there is a solution with the Reflection library. But my Reflection knowledge is not at that level.

Best regards.
 
Upvote 0
Top