Android Question Change the background color of a listview when click on it

Sberla

Active Member
Licensed User
Longtime User
Hello ,
How can I change the background color of a listview when I click on it ?

I have tried this but with no result :
B4X:
Sub lst_ItemClick (Position As Int, Value As  Object)

lst..TwoLinesLayout.Label.Color=Colors.Blue
lst.TwoLinesLayout.SecondLabel.Color=Colors.Blue
       
End Sub

Even this one:

Sub lst_ItemClick (Position As Int, Value As  Object)
    Dim cdwColor As  ColorDrawable
    cdwColor.Initialize(Colors.Blue,1dip)

lstFornitori.TwoLinesLayout.Label.Background=cdwColor
       
End Sub

Even with :
'    Dim bm As BitmapDrawable
'    Dim gd As GradientDrawable

But with not the desired success.
 

klaus

Expert
Licensed User
Longtime User
You can change the color of the selected item in a ListView with a JavaObject:
B4X:
Private jo = ListView1 As JavaObject
Private cdw As ColorDrawable
cdw.Initialize(Colors.Cyan, 0)
jo.RunMethod("setSelector", Array(cdw))
You can also change the devider color with:
B4X:
Private cdw As ColorDrawable
cdw.Initialize(Colors.Yellow, 0)
jo.RunMethod("setDivider", Array(cdw))
And the devider height with:
B4X:
jo.RunMethod("setDividerHeight", Array(5dip))
 
Upvote 0
Top