Android Question Some help with adapting TableExample

Lary Yenta

Member
Licensed User
Hey folks,

I am trying to get a list view of one of my Database Tables and I keep getting dumped out of my program.

The code I have written looks like:

B4X:
Sub Activity_Create(FirstTime As Boolean)
  Dim Cursor1 As Cursor
   Dim SQL1 As SQL
   Dim Qry As String
   Table1.Initialize(Me, "Medications", 4)
   Table1.AddToActivity(Activity, 0, 0dip, 100%x, 50%y)   
   Table1.SetHeader(Array As String("Name", "Dose", "Frequency", "Comments"))
 
   Qry = "SELECT meds.MedID, meds.MedName, meds.MedDose, meds.MedFreq, meds.MedComm FROM meds inner join users " & _
   "on users.ID = meds.UserID where meds.UserID = " & Main.MastUID
   'ToastMessageShow(Qry, True)
  Cursor1 = SQL1.ExecQuery(Qry)   
   For i = 0 To Main.MIDList.Size - 1
    Cursor1.Position = i
     'Cursor1.GetInt("MedID")
     Table1.AddRow(Array As String(Cursor1.GetString("MedName"), Cursor1.GetString("MedDose"), Cursor1.GetString("MedFreq"), Cursor1.GetString("MedComm")))
     'Table1.AddRow(Array As String("Row: " & i, "ccc", "ddd", "eee"))
   Next
   Table1.SetColumnsWidths(Array As Int(100dip, 100dip, 100dip, 100%x - 300dip))
   'Activity.AddMenuItem("Jump To 3000", "Jump1")
   'Activity.AddMenuItem("Jump To 0", "Jump2")
   
   'Table2.Initialize(Me, "Table2", 0)
   'Table2.AddToActivity(Activity, 0, 55%y, 100%x, 45%y)
   'Table2.LoadTableFromCSV(File.DirAssets, "citylist.csv", True)
End Sub
Any help would be appreciated

regards,

Lary
 

eurojam

Well-Known Member
Licensed User
are you sure that the cursor position which you derived from a list from your main activity has the same size like the query result in your cursor?
 

klaus

Expert
Licensed User
Why don't you use
For i = 0 To Cursor1.RowCount - 1
instead of
For i = 0 To Main.MIDList.Size - 1

What TableExample version are you speaking of.
In the Flexible Table Class you have a function LoadSqliteDB.
 

Lary Yenta

Member
Licensed User
Hi Klaus,

I tried loading the Table V1.42 but it would not load for me I got an error message as follows:

B4X:
  If FirstTime Then
'     File.Delete(File.DirDefaultExternal, DBFileName)   ' for testing to remove an old file

     If File.Exists(File.DirDefaultExternal, DBFileName) = False Then
       File.Copy(File.DirAssets, DBFileName, DBFileDir, DBFileName)  <=====Program paused here
     End If
     SQL1.Initialize(DBFileDir, DBFileName, True)
'     CreateTestDB   'Test for big numbers
   End If
Lary
 

Lary Yenta

Member
Licensed User
Hi Klaus,

Where would I find Version 1.43? I tried a search and the best I got was version 1.42.

Thanks,

Lary
 
Top