Get a colour from a listview and apply to a panel

o0spyder0o

Member
Licensed User
Longtime User
I can get a selected listview's item ok and assign the chosen item to a label like this:
label1.text = value
in the listview_itemclick event.

If the chosen item is 'Red' then the label's text will change to Red. All good.

However how can I change a panel's colour to red using the same method?
I see the panel uses panel1.color = colors.somecolor as the way to assign a color so how can I assign the selected item to this?
Cheers
 

o0spyder0o

Member
Licensed User
Longtime User
Hi Klaus

The listview contains colours, ie
listview.addsingleline("red")
and so on for yellow, blue etc.
I am able to use: Label1.text = value and that returns whatever color I have selected in the listview, which works fine.
I thought if the label is able to show a selected item as being 'red' then the panel color should be able to grab 'red' as the colors.(x) too but I'm unable to find a solution.
Something like Panel1.color = colors(value) would be what I'm seeking.

Cheers
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When you assign Label1.text = value you are assigning a text "red" and not a color code. In your Label it's written "red" but the text color is not changed.
You could use a code similar to this one:
B4X:
Sub ListView1_ItemClick((Position, Value)
.
.
 Select Value
 Case "red"
    Panel1.Color = Colors.Red 
 Case "yellow"
    Panel1.Color = Colors.Yellow
 Case "xxx"
    Panel1.Color = Colors.XXX
 End Select
End Sub
Another solution could be to define an Array of integer holding the color values.
B4X:
Dim PanelColors(10) as Int
PanelColors(0) = Colors.Red
PanelColors(1) = Colors.Yellow
PanelColors(2) = Colors.XXX
And
B4X:
Sub ListView1_ItemClick((Position, Value)
.
.
  Panel1.Color = PanelColors(Position)
End Sub
Best regards.
 
Upvote 0

o0spyder0o

Member
Licensed User
Longtime User
Thanks Klaus
I know it wasn't applying the text colour, I just wanted to see that the selected item was returning a value. I hoped that if the label was getting the string 'red' then I could apply that to the colors.x somehow.
However the array you posted works for me and will suit my purpose.
Many thanks.
 
Upvote 0
Top