Android Question Listview and labels colors

Sub7

Active Member
Licensed User
Longtime User
Hello, Why this code partially works?
When a codition enter, the text colors it's changed but it will applied for the whole loop even if code value is changes, instead defaulticon works fine.

B4X:
Sub Globals
Dim color as int
Dim ListView1 As ListView
Dim defaulticon, white, green, yellow, blue, red, violet As Bitmap
End sub
Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("1")

'db stuff

  white=LoadBitmap(File.DirAssets,"whitedot.png")
  green=LoadBitmap(File.DirAssets,"greendot.png")
  blue=LoadBitmap(File.DirAssets,"bluedot.png")
  red=LoadBitmap(File.DirAssets,"reddot.png")
  violet=LoadBitmap(File.DirAssets,"violetdot.png")
End sub

Sub load_click
Try
SQL1.BeginTransaction
c = SQL1.ExecQuery("SELECT code FROM codes LIMIT 80")
For i = 0 To c.RowCount - 1
c.Position = i
Dim code As Double
code = (c.GetDouble("code"))  'codes > 2, 1.1, 2.3, 5.9, 1.9, 2.3, 4.6


If code < 2 Then
colore = Colors.White
defaulticon = white
Else If code > 2 Then
colore = Colors.Magenta
defaulticon = green
Else if code > 3 Then
colore = Colors.Blue
defaulticon = blue
Else If code > 4 AND magnitude < 6 Then
colore = Colors.Red
defaulticon = red
End If

ListView1.TwoLinesAndBitmap.Label.TextColor = colore
ListView1.AddTwoLinesAndBitmap..............
'Listview settings


Next
SQL1.TransactionSuccessful
Catch
Log(LastException.Message)
End Try
SQL1.EndTransaction
End Sub

Thank you
 

eps

Expert
Licensed User
Longtime User
ListView text options work for all the elements in the ListView.

You can adjust to two colours, with a little trick, but apart from that they are 1 colour only. If you want lots of colours you will have to use ScrollView or ULV or something else.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hello, Why this code partially works?
When a codition enter, the text colors it's changed but it will applied for the whole loop even if code value is changes, instead defaulticon works fine.

B4X:
Sub Globals
Dim color as int
Dim ListView1 As ListView
Dim defaulticon, white, green, yellow, blue, red, violet As Bitmap
End sub
Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("1")

'db stuff

  white=LoadBitmap(File.DirAssets,"whitedot.png")
  green=LoadBitmap(File.DirAssets,"greendot.png")
  blue=LoadBitmap(File.DirAssets,"bluedot.png")
  red=LoadBitmap(File.DirAssets,"reddot.png")
  violet=LoadBitmap(File.DirAssets,"violetdot.png")
End sub

Sub load_click
Try
SQL1.BeginTransaction
c = SQL1.ExecQuery("SELECT code FROM codes LIMIT 80")
For i = 0 To c.RowCount - 1
c.Position = i
Dim code As Double
code = (c.GetDouble("code"))  'codes > 2, 1.1, 2.3, 5.9, 1.9, 2.3, 4.6


If code < 2 Then
colore = Colors.White
defaulticon = white
Else If code > 2 Then
colore = Colors.Magenta
defaulticon = green
Else if code > 3 Then
colore = Colors.Blue
defaulticon = blue
Else If code > 4 AND magnitude < 6 Then
colore = Colors.Red
defaulticon = red
End If

ListView1.TwoLinesAndBitmap.Label.TextColor = colore
ListView1.AddTwoLinesAndBitmap..............
'Listview settings


Next
SQL1.TransactionSuccessful
Catch
Log(LastException.Message)
End Try
SQL1.EndTransaction
End Sub

Thank you

When you change the property of a label in the B4A ListView, you change this property for all items.

To have different colors, you have to choose another solution: CustomListView, CheckList, UltimateListView, etc.
 
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
Thank you all!
i tried CustomListview and i managed to change the text color with CV1.DefaultTextColor = Colors.white
however for each looped row i need the first line with one color, an icon, and the text after crlf ad default text color, that's why i tried to use listview.

ICON I like colors
I don't like colors
ICON I like colors
I don't like colors

ty
 
Upvote 0

Sub7

Active Member
Licensed User
Longtime User
  • Like
Reactions: eps
Upvote 0
Top