Android Tutorial [B4X][B4XPages] SQL + xCLV Example

A simple, cross platform example that reads data from a database and adds it to a xCLV.


Database source:

The interesting code:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    B4XPages.SetTitle(Me, "SQL + xCLV Example")
    xui.SetDataFolder("sql example") 'required in B4J
    Dim dbname As String = "chinook_v1.db"
    If File.Exists(xui.DefaultFolder, dbname) = False Then File.Copy(File.DirAssets, "chinook.db", xui.DefaultFolder, dbname)
    #if B4J
    'B4J SQL object can access many types of databases (same as B4A JdbcSQL).
    sql.InitializeSQLite(xui.DefaultFolder, dbname, False)
    sql.Initialize(xui.DefaultFolder, dbname, False)
    #End If
    Dim rs As ResultSet = sql.ExecQuery2($"SELECT AS ArtistName, albums.title AS AlbumTitle FROM albums, artists 
        WHERE albums.artistid = artists.artistid"$, Null)
    Do While rs.NextRow
        Dim rd As RecordData = CreateRecordData(rs.GetString("ArtistName"), rs.GetString("AlbumTitle"))
        CustomListView1.Add(CreateItem(rd), rd)
End Sub

Private Sub CreateItem(rd As RecordData) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Root.Width, 60dip)
    'labels will point to the last loaded views with the set name.
    lblAlbum.Text = rd.AlbumName
    lblArtist.Text = rd.ArtistName
    Return p
End Sub


  • SQL + xCLV
    347 KB · Views: 900


Active Member
Licensed User
Thank you so much Erel - This is very helpful ๐Ÿ‘๐Ÿ‘๐Ÿ‘


Licensed User
Longtime User
As "few" of you know, I'm mostly a nuisance ๐Ÿ˜„ , so...

A good example would also be the "porting" of SQLiteViewer for B4XPages, with B4XTable.

It would only be necessary to convert to B4XPages ๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜

another option for @LucaMs wishes, it would be JRDC2 to B4Xtable and B4XCustomListview

Last edited: