Android Question To show formatted text in B4Xtable text columns

toby

Well-Known Member
Licensed User
Longtime User
I want to have a Text column filled with formatted text created on the fly, not from database. I thought I could simply assign a CSBuilder value to the cell to show some formatted text since the cell layout consists of a single label within a panel. But so far I haven't been able to make it work. Following code only shows plain text with formatting lost.

Following code block results in plain text, not formatted:
    csb.Initialize.Append("Bon appetite restaurant->").Append("12345 main road").RelativeSize(2.0).Color(Colors.Magenta).Append("$15").Pop.Pop.Append(", paid").PopAll
    cols(0)=csb

What did I miss?

Or the B4xTable with flags example shows the only way to achieve this?

TIA
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It cannot work as the data is inserted to a database and later retrieved as a string.

You can do it by storing the CSBuilders outside of the database:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XTable1 As B4XTable
    Private ColumnKey, Column1 As B4XTableColumn
    Private CSBuilders As Map
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    ColumnKey = B4XTable1.AddColumn("key", B4XTable1.COLUMN_TYPE_NUMBERS)
    Column1 = B4XTable1.AddColumn("Col 1", B4XTable1.COLUMN_TYPE_VOID)
    B4XTable1.AddColumn("Col 2", B4XTable1.COLUMN_TYPE_NUMBERS)
    B4XTable1.VisibleColumns.RemoveAt(0) 'remove the key column
    CSBuilders.Initialize
    Dim data As List
    data.Initialize
    For i = 0 To 77
        Dim cs As CSBuilder
        cs.Initialize
        cs.Bold.Color(xui.Color_Red).Append("Item ").PopAll.Color(xui.Color_Blue).Append(i).PopAll
        CSBuilders.Put(i, cs)
        data.Add(Array(i, i * 17))
    Next
    B4XTable1.SetData(data)
End Sub

Private Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim id As Long = B4XTable1.VisibleRowIds.Get(i)
        If id = 0 Then Continue
        Dim row As Map = B4XTable1.GetRow(id)
        Dim key As Int = row.Get(ColumnKey.Id)
        Dim cs As CSBuilder = CSBuilders.Get(key)
        XUIViewsUtils.SetTextOrCSBuilderToLabel(Column1.CellsLayouts.Get(i + 1).As(B4XView).GetView(Column1.LabelIndex), cs)
    Next
End Sub

1642087355025.png
 
Upvote 0
Top