B4J Tutorial [B4X] B4XTable sample working with SQLite

[B4X] B4XTableSample​

A sample project to demonstrate loading SQLite data into B4XTable
GitHub: https://github.com/pyhoon/B4XTableSample-B4X

Features​

  • Use OkHttpUtils to download json file from a URL
  • Parse the JSON as List and extract each item as Map
  • Store the data into SQLite database
  • Perform CRUD functions like add, retrieve, edit, delete rows
  • Use B4XPreferencesDialog to show the panel for input
  • Jump to a row in B4XTable

Why I created this sample project​

B4X developers often confuse or don't understand how to load and save data between an SQL database and use B4XTable to display the data. B4XTable uses a in-memory database for it's internal operation. It has a single table name "data" with columns start with c0, c1, c2 and so on. Developers should not mix the internal db with their actual database. This sample shows how we can interact and work with B4XTable by connecting it to a SQLite database. In fact, B4XTable is so powerful that it actually can work with CSV files or non SQL database.

Screenshots​

B4A

B4J
 

Attachments

  • B4XTableSample.zip
    20.2 KB · Views: 54
Last edited:

aeric

Expert
Licensed User
Longtime User
Error trying to run:

In line 141:
B4X:
    PrefDialog.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
There was a warning:
Steps:
1. Extract the project. You will get a folder name "source".
2. Open a project e.g B4J
3. Run Debug. The file template.json should be copied from Shared Files folder to Files folder.
4. Click "Sync" button in Files Manager tab.

Alternatively, you can manually use the comment link:
B4X:
'Sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
 

aeric

Expert
Licensed User
Longtime User
Sorry, i'm using B4J version 10.00 and the macro's are not supported...

I commented out all the macro lines...
I didn't think about the shared files folder...
OK.
I think you also commented the CustomBuildAction
B4X:
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"

CustomBuildAction is seldom used but I use it to reduce the zipped file size and avoid deploying redundant file.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
If you add row Selection - for current row, editing - or when returns from editing, add new, delete record, will be super!
I am not really get you but this is just an example. Anyone can modify it for other use case.
 
Top