B4J Question Need Help With Tableview

tufanv

Expert
Licensed User
Longtime User
Hello ,

I need to colorize some texts at tableview. I checked Erel's tutorial about adding labels to table view but I have a problem : Currently I am using the below code:

B4X:
Dim row(7) As Object
Dim img_http As Image

img_http.Initialize(File.DirAssets, id&".png")
                    pictoImage.Initialize("ImageView")
pictoImage.SetImage(img_http)
row(0) = pictoImage

                row(1) = symbol
                row(2) = "$ " &price_usd
                row(3) = "% "&percent_change_24h
                row(4) = price_btc
                If volume_usd="" Or volume_usd=Null Or volume_usd="null" Then
                    row(5)="-"
                Else
                    row(5) = "$ " & NumberFormat2(volume_usd,0,0,0,True)
                    '                row(5)=volume_usd
                End If
               
                row(6) = rank


Becuase I am using an imageview in row(0) , I cant Use Erel's code for adding labels to tableview. How Can I coloriz the third row to green for example. I need a way to do this

TY
 

stevel05

Expert
Licensed User
Longtime User
I think this should work (haven't tested it though)

B4X:
Dim row(7) As Object
Dim img_http As Image

img_http.Initialize(File.DirAssets, id&".png")
                    pictoImage.Initialize("ImageView")
pictoImage.SetImage(img_http)
row(0) = pictoImage

                row(1) = symbol
                row(2) = "$ " &price_usd
                Dim L As Label
                L.Initialize("")
                L.Text = "% "&percent_change_24h
                If percent_change_24h >= 0 Then
                   L.TextColor = fx.Colors.Green
                Else
                   L.TextColor = fx.Colors.Red
                End If
                row(3) = L
                row(4) = price_btc
                If volume_usd="" Or volume_usd=Null Or volume_usd="null" Then
                    row(5)="-"
                Else
                    row(5) = "$ " & NumberFormat2(volume_usd,0,0,0,True)
                    '                row(5)=volume_usd
                End If
            
                row(6) = rank
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
When I tried the same thing it gave me an error like : cant cast to string
but this works perfect !
Thanks !
I think this should work (haven't tested it though)

B4X:
Dim row(7) As Object
Dim img_http As Image

img_http.Initialize(File.DirAssets, id&".png")
                    pictoImage.Initialize("ImageView")
pictoImage.SetImage(img_http)
row(0) = pictoImage

                row(1) = symbol
                row(2) = "$ " &price_usd
                Dim L As Label
                L.Initialize("")
                L.Text = "% "&percent_change_24h
                If percent_change_24h >= 0 Then
                   L.TextColor = fx.Colors.Green
                Else
                   L.TextColor = fx.Colors.Red
                End If
                row(3) = L
                row(4) = price_btc
                If volume_usd="" Or volume_usd=Null Or volume_usd="null" Then
                    row(5)="-"
                Else
                    row(5) = "$ " & NumberFormat2(volume_usd,0,0,0,True)
                    '                row(5)=volume_usd
                End If
           
                row(6) = rank
 
Upvote 0
Top