Android Question Need help finding best direction to take regarding table data output . . .

aedwall

Active Member
Licensed User
Longtime User
I have text data that needs to be displayed, probably in a table, to make formatting easier.

The data is such that various characters in each cell of the table are strings (or equivalent), which have different colors for some of the different characters. An example might be: "Jup/Sat =15/6.49-46 ( 6) -14.35-52", where the "49" is shown in red, while the rest is black or other colors.

The table would be something like this in the cells going across the row:

Column 0 Column 1 Column 2 Column 3
"Jup/Sat" "=" "15/6.49-46 ( 6)" "-14.35-52"

I can do this using EditText:

Sample code:
t1 = "Jup/Sat    =15/6."
cs.Color(Colors.Black).Append(t1)
cs.Pop
 
t2 = "49"
cs.Color(Colors.Red).Append(t2)
cs.Pop

t3 = "-46 ( 6)     -14.35-52"
cs.Color(Colors.Black).Append(t3)
cs.PopAll
 
EditText1.Text = cs
B4X:

But this has been a nightmare to keep the formatting lined up for all the different rows of data present.

I have tried to use the TableView class, but I can't seem to get it to recognize colors using CSBuilder.

Can anyone suggest to me how to best approach this issue? Should I investigate BCTextEngine or RichString or some other library? Thank you.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I`m not 100% sure that I understand the layout that you are trying to create. With BCTextEngine you should use the span tag to create tables:
B4X:
    s = $"
    ${TableRow($"[color=#ff0000][b]123[/b][/color]"$, "AAAbb", "bCCC")}
    ${TableRow($"[color=#ff0000][b]4536[/b][/color]"$, "AbAA", "CCC")}
    ${TableRow($"[color=#ff0000][b]1[/b][/color]"$, "AAAb", "C")}
    ${TableRow($"[color=#ff0000][b]-232[/b][/color]"$, "AA", "[color=blue]b[/color]CCC")}
    "$
    BBCodeView1.Text = s


Sub TableRow(Field1 As String, Field2 As String, Field3 As String) As String
    Return $"[Span MinWidth=100 Alignment=right]${Field1}[/Span][Span MinWidth=100 Alignment=center]${Field2}[/Span][Span MinWidth=100 Alignment=left]${Field3}[/Span]"$
End Sub

1744089318697.png
 
Upvote 0
Top