B4J Question Best Way To Load Up CSV File

cklester

Well-Known Member
Licensed User
I have built the following sub that loads a CSV file selected by the user. What's the actual pattern for this functionality?

B4X:
Sub btn_LoadRecipients_Click
    Dim fc As FileChooser
    Dim fn As String
    fc.Initialize
    fc.Title = "Select Recipients File"
    fc.SetExtensionFilter("CSV Files",Array As String("*.csv"))
    fn = fc.ShowOpen(B4XPages.GetNativeParent(Me))
    If fn <> "" Then
        Dim csv As CSVParser
        Dim isFirst As Boolean = True
        csv.Initialize
        Dim table As List = csv.Parse(File.ReadString(File.GetFileParent(fn),File.GetName(fn)),",",False)
        For Each row() As String In table
            'work with row
            If isFirst Then
                listHeaders = row
                isFirst = False
            Else
                'add to list_Recipients (B4XView/ListView)
                
            End If
'            Log(row(0))
        Next
    End If
End Sub
 

cklester

Well-Known Member
Licensed User
I'm only showing one column of the data for now, so I'm just dropping it into a ListView. Is it still better to use a B4XTable?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…