Android Question How to change B4XTable Customized column value color(SOLVED)

Daniel44

Active Member
Licensed User
I have this field in a B4XTable:

COLUMN = TBLTRAD.AddColumn("BESTNUMBERS",TBLTRAD.COLUMN_TYPE_TEXT)
CreateCustomFormat(COLUMN)
SetColumnAlignment("BESTNUMBERS",Gravity.LEFT)

This column (BESTNUMBER) fetchs several number. I don't know if it's possible to change color to a mayor value inside there
I'm trying with a Erel's example this

Here I'm trying to fetch the best number and change its color but I don't know how to implement this or if it's possible

B4X:
Private Sub CreateCustomFormat (c As B4XTableColumn)
    Dim formatter As B4XFormatter
    formatter.Initialize
    c.Formatter = formatter
    
    c.Width = 90
    Dim Positive As B4XFormatData = c.Formatter.NewFormatData
    Dim QRY As String
    Dim num As Int
    QRY = "SELECT MAX(allnumbers) FROM table1"
    ops.Initialize
    num =ops.SQL1.ExecQuerySingleResult(QRY)
    Log("BETTER NUMBER: " &num)
    
    ....here it would be the right code
    
    Positive.TextColor =xui.Color_Red
  
    Positive.FormatFont = xui.CreateDefaultBoldFont(4)
    Positive.FormatFont = xui.CreateDefaultFont(20)
 
    c.Formatter.AddFormatData(Positive, 0, c.Formatter.MAX_VALUE, True) 'Inclusive (zero included)
    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, 0, False)
End Sub

I need to change only the color in that value. Not the whole row color but the value color. Thank you in Advance.
 

Mahares

Expert
Licensed User
Longtime User
COLUMN = TBLTRAD.AddColumn("BESTNUMBERS",TBLTRAD.COLUMN_TYPE_TEXT)
CreateCustomFormat(COLUMN)
Column should be declared as NUMBERS:
B4X:
COLUMN = TBLTRAD.AddColumn("BESTNUMBERS",TBLTRAD.COLUMN_TYPE_NUMBERS)
CreateCustomFormat(COLUMN)
formatter.GetDefaultFormat.TextColor = B4XTable1.TextColor   'you may need this line to return to default color
and sub CreateCustomFormat should be:
B4X:
Private Sub CreateCustomFormat (c As B4XTableColumn)
    Dim formatter As B4XFormatter
    formatter.Initialize
    c.Formatter = formatter
    
    c.Width = 90
    Dim Positive As B4XFormatData = c.Formatter.NewFormatData
    Dim QRY As String
    Dim num As Int
    QRY = "SELECT MAX(allnumbers) FROM table1"
    ops.Initialize
    num =ops.SQL1.ExecQuerySingleResult(QRY)
    Log("BETTER NUMBER: " &num)
    Positive.TextColor =xui.Color_Red
  
    'Positive.FormatFont = xui.CreateDefaultBoldFont(4)
    Positive.FormatFont = xui.CreateDefaultFont(20)
 
    c.Formatter.AddFormatData(Positive, num, c.Formatter.MAX_VALUE, True)    '<------------mahares
    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, 0, False)
End Sub
Of course untested because I do not have your project in hand.
 
Upvote 0

Daniel44

Active Member
Licensed User
Hey Mahares thank you for answering. It works. My best number is colored to red, but to change the column to TYPE_NUMBER doesn't fetch all number. I'll show you how table shows my concats numbers.
My sqlite query groups all number by group_concat(s)AS BESTNUMBERS, and I can see when i change to TYPE_NUMBER_COLUMN just fetch some number but not all of them. Thank you Mahares
 

Attachments

  • GROUPED NUMBERS.png
    59.7 KB · Views: 218
  • WITH TYPENUMBER COLUMN.png
    13 KB · Views: 229
Upvote 0

Daniel44

Active Member
Licensed User
The first image is how my query fetchs all my numbers and as you can see they're strings becasue of grouping. That's the reason i was asking if it posible. If I change the type of column to text_type and I try to use the function obiously it doesn't change the color of my mayor number there coz formatter works with integer values, but when i change to number_type my query it doesn't work correctly as it has seen in the second image. Thank you.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
That's the reason i was asking if it posible. If I change the type of column to text_type
You cannot apply CusomFormat in B4Table unless the column is : COLUMN_TYPE_NUMBERS. Your image #1 (groupednumbers) shows the lsit of numbers concatenated to form a string. What you can do is: extract the maximum number making the string in the given cell of each row using Regex.Split, a list and sort the list and put in in another B4XTable column that you create and add to the table. Then, you can apply CustomFormat to that numbers column. If you still have problems, you may want to create a small project and someone in the forum will help you. See screenshot of what I mean when the table data is displayed.
 

Attachments

  • B4XTableMaxNumberHighlighted.png
    15.1 KB · Views: 215
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…