iOS Question Dynamically Adding String to TableView

kc1

Member
Licensed User
Longtime User
I would like to scan for Bluetooth devices and then build a list dynamically.

I looked at examples for TableView and tried to incorporate them but nothing I tried worked.

I tried this code from a tutorial and my App crashed:
B4X:
Dim items As List = TableView1.GetItems(0)
Dim tc As TableCell 'create a new item
tc.InitializeSingleLine("New Item!")
items.InsertAt(0, tc)
TableView1.ReloadSection(0)

I was able to build my table in Application_Start using AddSingleLine with no problem, but it didn't work dynamically in BLEmanager_DeviceFound.

Below are relevant sections of my code, and I need help adding to an empty TableView:
B4X:
Sub Process_Globals
   Private TableViewDeviceList As TableView
End Sub

Private Sub Application_Start (Nav As NavigationController)
   TableViewDeviceList.Initialize("TableViewDeviceList", False)
   Page1.RootPanel.AddView(TableViewDeviceList, 200, 200, 100%x, 100%y)
   'TableViewDeviceList.AddSingleLine("Test")
End Sub

Sub BLEmanager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
   Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
  
   'WHAT DO I DO HERE TO ADD Name TO TableViewDeviceList??
End Sub

Please help!

Thank you,
kc
 

kc1

Member
Licensed User
Longtime User
Problem solved!! :)

Found that I need to call ReloadAll:
B4X:
Sub BLEmanager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
   Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
 
   TableViewDeviceList.AddSingleLine(Name)
   TableViewDeviceList.ReloadAll
End Sub

:)
 
Upvote 0
Top