Android Code Snippet [B4X] [LOA] ListOfArrays <--> B4XTable

Visualize a LOA with B4XTable:
Code: Copy
Private Sub ShowLoaInTable(loa As ListOfArrays, table As B4XTable, DateColumns As List)
    table.Clear
    If loa.IsEmpty Then Return
    If loa.FirstRowIsHeader = False Then
        Log("Missing header names")
        Return
    End If
    For Each col As Int In loa.ColumnIndices
        Dim ColType As Int
        Dim ColName As String = loa.Header(col)
        If Initialized(DateColumns) And DateColumns.IndexOf(ColName) > -1 Then
            ColType = table.COLUMN_TYPE_DATE
        Else
            Dim FirstValue As Object = loa.GetValueDefault(0, col, "")
            If FirstValue Is String Then
                ColType = table.COLUMN_TYPE_TEXT
            Else
                ColType = table.COLUMN_TYPE_NUMBERS
            End If
        End If
        table.AddColumn(ColName, ColType)
    Next
    table.SetData(B4XCollections.SubList(loa.mInternalArray, loa.mFirstDataRowIndex, loa.mInternalArray.Size))
End Sub

Usage example, based on DBQuery: https://www.b4x.com/android/forum/threads/b4x-loa-dbquery-sql-made-easy.170560/#content
Code: Copy
ShowLoaInTable(db.ExecQuery($"SELECT name, age As [Nice Age], created_at FROM table1"$, Null), B4XTable1, Array("created_at"))

The last parameter is an array with the names of the columns that will be treated as date columns. Pass Null if not needed.

1775735170010.png


Example is attached.
 

Attachments

Back
Top