Android Question How to make the text in the column wrapped in B4XTable?

daiweisc

Member
How to make the text in the column wrapped in B4XTable?
2023-05-08_085116.png
 

daiweisc

Member
The thread in B4J is invalid.
B4X:
'    B4XTable2.RowHeight = 100dip   
    B4XTable2.SearchVisible = False
    B4XTable2.BuildLayoutsCache(B4XTable2.MaximumRowsPerPage)
    Private ID2Column As B4XTableColumn = B4XTable2.AddColumn("ID", B4XTable2.COLUMN_TYPE_TEXT)
    ID2Column.Width = 50dip
    Private TypeColumn As B4XTableColumn = B4XTable2.AddColumn("管子类型", B4XTable2.COLUMN_TYPE_TEXT)
    SetWrapText(TypeColumn)
    Private RoughColumn As B4XTableColumn = B4XTable2.AddColumn("等值粗糙度(mm)", B4XTable2.COLUMN_TYPE_TEXT)
    RoughColumn.Width = 100dip
    SetWrapText(RoughColumn)
    Private data2 As List = parser.Parse(File.ReadString(File.DirAssets, "Table2.csv"), ",", True)
    B4XTable2.SetData(data2)


Private Sub SetWrapText(Col As B4XTableColumn)
    For i = 1 To Col.CellsLayouts.Size - 1
        Private p As B4XView = Col.CellsLayouts.Get(i)
        Private lbl As Label = p.GetView(Col.LabelIndex)
        lbl.WrapText = True
    Next
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The text in the column is still unwrapped in B4XTable.
Call SetWrapText sub in B4XTable2_DataUpdated . You have to declare RoughColumn in Globals
B4X:
Sub B4XTable2_DataUpdated  
    SetWrapText(RoughColumn)
End Sub

Private Sub SetWrapText(Col As B4XTableColumn)
    For i = 1 To Col.CellsLayouts.Size - 1
        Dim p As B4XView = Col.CellsLayouts.Get(i)
'        Dim lbl As Label = p.GetView(0)    
        Dim lbl As Label = p.GetView(Col.LabelIndex)
        Dim lb4x As B4XView =lbl    
        #if B4A 
            lbl.SingleLine =False
            lb4x.textColor=xui.Color_Red
        #end if
        #if B4J
            lbl.WrapText = True    
            lb4x.textColor =xui.Color_Magenta
        #End If
    Next
End Sub
 
Upvote 0

daiweisc

Member
Thanks for reply. But it is unwrapped. The below is the code :

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    
    Public SQL1 As SQL
    Private B4XTable1 As B4XTable
    Private B4XTable2 As B4XTable   
    
    Public TypeColumn As B4XTableColumn
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Table1")
    Private parser As CSVParser
    parser.Initialize
    
    'create the columns
    B4XTable1.SearchVisible = False
    Private ID1Column As B4XTableColumn = B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_TEXT)
    ID1Column.Width = 50dip
    Private DNColumn As B4XTableColumn = B4XTable1.AddColumn("DN/mm", B4XTable1.COLUMN_TYPE_TEXT)
    DNColumn.Width = 100dip
    Private DiColumn As B4XTableColumn = B4XTable1.AddColumn("Di/mm", B4XTable1.COLUMN_TYPE_TEXT)
    DiColumn.Width = 100dip
    Private data1 As List = parser.Parse(File.ReadString(File.DirAssets, "Table1.csv"), ",", True)
    B4XTable1.SetData(data1)

'    B4XTable2.RowHeight = 80dip
    B4XTable2.SearchVisible = False
    Private ID2Column As B4XTableColumn = B4XTable2.AddColumn("ID", B4XTable2.COLUMN_TYPE_TEXT)
    ID2Column.Width = 50dip
'    Private TypeColumn As B4XTableColumn = B4XTable2.AddColumn("管子类型", B4XTable2.COLUMN_TYPE_TEXT)
    TypeColumn = B4XTable2.AddColumn("管子类型", B4XTable2.COLUMN_TYPE_TEXT)
    SetWrapText(TypeColumn)
    Private RoughColumn As B4XTableColumn = B4XTable2.AddColumn("等值粗糙度(mm)", B4XTable2.COLUMN_TYPE_TEXT)
    RoughColumn.Width = 140dip
    Private data2 As List = parser.Parse(File.ReadString(File.DirAssets, "Table2.csv"), ",", True)
    B4XTable2.SetData(data2)
'    B4XTable2.Refresh
End Sub

Private Sub SetWrapText(Col As B4XTableColumn)
    For i = 1 To Col.CellsLayouts.Size - 1
        Dim p As B4XView = Col.CellsLayouts.Get(i)
'        Dim lbl As Label = p.GetView(0)   
        Dim lbl As Label = p.GetView(Col.LabelIndex)
        Dim lb4x As B4XView =lbl   
        #if B4A
            lbl.SingleLine =False
            lb4x.textColor=xui.Color_Red
        #end if
        #if B4J
            lbl.WrapText = True   
            lb4x.textColor =xui.Color_Magenta
        #End If
    Next
End Sub

1684540304161.png
 
Upvote 0
Top