Android Question B4XTable - Custom Format

Noelkman

Member
Licensed User
Longtime User
I took the below example and it is doing bold font and the postfix but not the color red - why?
This drives me nuts.
Actually I have a field that can have 1, 2, 3. I want the 1 and the 2 to become a different color. 3 should stay black.
Would that work at all? If yes how?


B4X:
Sub CreateCustomFormat (c As B4XTableColumn)
    Dim Formatter As B4XFormatter
    Formatter.Initialize
    c.Formatter = Formatter
    Dim Positive As B4XFormatData = c.Formatter.NewFormatData
    
    Positive.TextColor = B4XTable1.TextColor
    Positive.FormatFont = xui.CreateDefaultFont(16)
    c.Formatter.AddFormatData(Positive, 1, c.Formatter.MAX_VALUE, True) 'Inclusive (zero included) 'c.formatter.max_value
    Dim Negative As B4XFormatData = c.Formatter.CopyFormatData(Positive)
    Negative.TextColor = xui.Color_Red
    Negative.FormatFont = xui.CreateDefaultBoldFont(16)
    Negative.Prefix = ""
    Negative.Postfix = " !"
    c.Formatter.AddFormatData(Negative,c.Formatter.MIN_VALUE, 3, False)
End Sub
 

Mahares

Expert
Licensed User
Longtime User
Actually I have a field that can have 1, 2, 3. I want the 1 and the 2 to become a different color. 3 should stay black.
Try something like this or you could add the code to your CreateCustomFormat
B4X:
Sub CreateCustomFormat (c As B4XTableColumn)
    formatter.Initialize
    c.Formatter = formatter
    c.Formatter.GetDefaultFormat.TextColor =Colors.Black
   
    Dim notthree As B4XFormatData= c.Formatter.NewFormatData
    notthree.TextColor = Colors.Red  '1 and 2 are red, rest black
    c.Formatter.AddFormatData(notthree,1, 2, True)
End Sub
 
Upvote 0

Noelkman

Member
Licensed User
Longtime User
I tried your code with the same effect.
To see the difference I added notthree.FormatFont = xui.CreateDefaultBoldFont(16)
The font is set the color isn't. Crazy stuff.


B4X:
    Dim PriColumn As B4XTableColumn
    PriColumn = B4XTable1.AddColumn("Pri", B4XTable1.COLUMN_TYPE_NUMBERS)
    PriColumn.Searchable = True
    PriColumn.Width = 40dip
    
    CreateCustomFormat(PriColumn)
        
    LoadData
 
Upvote 0

Noelkman

Member
Licensed User
Longtime User
Got it working and your example brought me to the solution somehow.
I have to mention maybe that I'm running this great table in a B4X Custom Dialog.
After loading the data I did two lines:
B4X:
    B4XTable1.Refresh
    Sleep(0)

and boom the color where red.

But just for my understanding why is the font set with the formatter but the coloring is not?
 
Upvote 0
Top