Android Question Tips to fill and get online data in a B4XTable

asales

Expert
Licensed User
Longtime User
I retrive the profiles data online using this (great) lib MagicAPI.
The lib return all the data of the profiles as a maps in a list.
I show only the ID, name and phone in a B4XTable, using the basic approach: make a loop with "for each", fill the ListData and SetData(ListData).
When I click in the cell, I get the ID and made a loop (for each) again in the ListData to find the ID and get all the data.

This is the correct (or better) approach: to make 2 loops to get the data?

B4X:
Sub GetOnlineData
    mg.Search("profiles", "vendor", "1")
    wait for mg_Search(x As List, success As Boolean)
    If success = True Then
        ListData = x
        FillB4XTable(ListData)
End Sub

Sub FillB4XTable(x As List)
    Dim Data As List
    Data.Initialize
        
    For Each col As Map In x
        Dim row(3) As Object
        row(0) = col.Get("name")
        row(1) = col.Get("phone")
        row(2) = col.Get("id")
        Data.Add(row)
    Next
End Sub

Sub B4XTable_CellClicked (ColumnId As String, RowId As Long)
    Dim RowData As Map = B4XTable.GetRow(RowId)
    Dim id As Int = RowData.Get("ID")
    For Each col As Map In ListData
        If id = col.Get("ID") Then
            Log(col.Get("ID"))
            Log(col.Get("name"))
            Log(col.Get("phone"))
            Log(col.Get("mobile"))
            Log(col.Get("postal"))
            Log(col.Get("city"))
            Log(col.Get("mail"))
            Log(col.Get("code"))
            Log(col.Get("birthday"))
            Log(col.Get("vendor"))
            Return
        End If
    Next
End Sub
 
Top