Basic sample of database bound to listview

jalle007

Active Member
Licensed User
Longtime User
HI

I know its basic task but I don't have luck with completing it.
I would need basic sample in using existing SQLite database in program.
I have DButilis included in my project also vicevi.db is under my project folder,

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim dbName="vicevi.db"
   'DBUtils.CopyDBFromAssets(dbName)
   If FirstTime Then
      SQL.Initialize(File.DirRootExternal, dbName, True)
   End If
   Activity.LoadLayout("Layout1")
   Dim ListView1 As ListView
   ListView1.Initialize("ListView1")
    
   DBUtils.ExecuteListView(SQL, "SELECT text FROM vic", Null, 0, ListView1, True)
      
End Sub

"an error has occured in line 20 SQL.initialize....unable to open database file"

Please tell me what am I doing so wrong here ?
 

jalle007

Active Member
Licensed User
Longtime User
Mr

Now after I changed code to this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layout1")
   Dim dbName="vicevi.db"

   If FirstTime Then
   Dim db=DBUtils.CopyDBFromAssets(dbName)
   SQL1.Initialize (db, dbName, True)
   End If

   'If FirstTime Then
   '   SQL.Initialize(File.DirRootExternal, dbName, True)
   'End If
   
   Dim ListView1 As ListView
   ListView1.Initialize("ListView1")
    
   DBUtils.ExecuteListView(SQL1, "SELECT text FROM vic", Null, 0, ListView1, False)
      
End Sub

I see listview is populated in code but NOTHING is shown in the screen !?! :sign0163:
 
Upvote 0

jalle007

Active Member
Licensed User
Longtime User
Mr

OK I found working sample:

HTML:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Layout1")

   Dim dbName="vicevi.db"
   
   If FirstTime Then
   Dim db=DBUtils.CopyDBFromAssets(dbName)
   SQL1.Initialize (db, dbName, True)
   End If

   DBUtils.ExecuteListView(SQL1, "SELECT text FROM vic", Null, 0, ListView1,False)
End Sub

Now my next concern is that there is no much space in listview to show whole text for an item.
Is there a way to set listview item to auto height
 
Upvote 0
Top