ListView - with different TextColor per Line ...

Hubert Brandel

Active Member
Licensed User
Longtime User
Hi,

I use a Listview with the TwoLinesLayout setting:

B4X:
lvListeGE.Clear
lvListeGE.Color = Colors.DarkGray
lbl2 = lvListeGE.TwoLinesLayout.SecondLabel
lbl2.TextColor = Colors.White

lbl1 = lvListeGE.TwoLinesLayout.Label
lbl1.TextColor = Colors.Yellow
lbl1.TextSize  = lbl2.TextSize
...
sLabel1 = ... sStatus & ...
sLabel2 = ... "   "     & cur.GetString("GeraeteNr") ...
lvListeGE.AddTwoLines2( sLabel1,sLabel2, cur.GetString("sMiGeNr") )

First line in yellow, second in white ... looks good.

But now I was asked, if I can change the color of the first line per lable depending on values of the data ...

if fieldX="1" then first line in RED
if fieldX="0" then first line in BLUE
if fieldXS"2" then first line in GREEN
Rest in yellow ...

Is there a way to do this ?
 

Informatix

Expert
Licensed User
Longtime User
Hi,

I use a Listview with the TwoLinesLayout setting:

B4X:
lvListeGE.Clear
lvListeGE.Color = Colors.DarkGray
lbl2 = lvListeGE.TwoLinesLayout.SecondLabel
lbl2.TextColor = Colors.White

lbl1 = lvListeGE.TwoLinesLayout.Label
lbl1.TextColor = Colors.Yellow
lbl1.TextSize  = lbl2.TextSize
...
sLabel1 = ... sStatus & ...
sLabel2 = ... "   "     & cur.GetString("GeraeteNr") ...
lvListeGE.AddTwoLines2( sLabel1,sLabel2, cur.GetString("sMiGeNr") )

First line in yellow, second in white ... looks good.

But now I was asked, if I can change the color of the first line per lable depending on values of the data ...

if fieldX="1" then first line in RED
if fieldX="0" then first line in BLUE
if fieldXS"2" then first line in GREEN
Rest in yellow ...

Is there a way to do this ?

No. The item properties are set for all items. There's a trick to have two different layouts (by using TwoLines and TwoLinesBitmap in the same ListView) but, in your case, you should better use a ScrollView. Try the CheckList class or the CustomListView class. They are made to replicate a ListView.
 
Upvote 0
Top