Android Question b4xTable with buttons

Scantech

Well-Known Member
Licensed User
I am running into an error. I am trying to create edit column like the example provide at the forum. My codes is as following.
B4X:
Sub InitTableandSql(FirstTime As Boolean)
    Try

        If FirstTime Or blnFileAvailable = False Then
            'check external first
            If File.Exists(File.DirRootExternal, Starter.DiagReportDatabase & "diagreport.db") Then
                sql.Initialize(File.DirRootExternal, Starter.DiagReportDatabase & "diagreport.db", False)
                blnFileAvailable = True
            Else If File.Exists(File.DirInternal, Starter.DiagReportDatabase & "diagreport.db") Then
                sql.Initialize(File.DirInternal, Starter.DiagReportDatabase & "diagreport.db", False)
                blnFileAvailable = True
            Else
                blnFileAvailable = False
            End If
        End If
           
        Activity.LoadLayout("diagreporttable")

        'this is for edit and delete button
        editCol = B4XTable1.AddColumn("Edit", B4XTable1.COLUMN_TYPE_TEXT)
        editCol.Sortable = False
        editCol.Width = 127dip
       
        B4XTable1.NumberOfFrozenColumns = 1
       
        B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_NUMBERS)
        B4XTable1.AddColumn("RO", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Date", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("VIN", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Year", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Make", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("Model", B4XTable1.COLUMN_TYPE_TEXT)
        B4XTable1.AddColumn("File Name", B4XTable1.COLUMN_TYPE_TEXT)
       
        Dim Data As List
        Data.Initialize
       
        If blnFileAvailable = True Then
            Dim rs As ResultSet = sql.ExecQuery("SELECT ID, RO, Date, VIN, Year, Make, Model, FileName FROM diagnosticlog")
            Dim startTime As Long = DateTime.Now
           

            Do While rs.NextRow
                Dim row(8) As Object
                row(0) = rs.GetDouble("ID")
                row(1) = rs.GetString("RO")
                row(2) = rs.GetString("Date")
                row(3) = rs.GetString("VIN")
                row(4) = rs.GetString("Year")
                row(5) = rs.GetString("Make")
                row(6) = rs.GetString("Model")
                row(7) = rs.GetString("FileName")

                If row(0) = Null Then row(0) = ""
                If row(1) = Null Then row(1) = ""
                If row(2) = Null Then row(2) = ""
                If row(3) = Null Then row(3) = ""
                If row(4) = Null Then row(4) = ""
                If row(5) = Null Then row(5) = ""
                If row(6) = Null Then row(6) = ""
                If row(7) = Null Then row(7) = ""
               
                Data.Add(row)
            Loop
            Log("Index time: " & (DateTime.Now - startTime) & " ms")

            rs.Close

            Dim startTime As Long = DateTime.Now

            B4XTable1.SetData(Data)
        '    B4XTable1.MaximumRowsPerPage = 1
       
            For i = 1 To editCol.CellsLayouts.Size - 1
                Dim p As B4XView = editCol.CellsLayouts.Get(i)
                p.AddView(CreateButton("btnEdit", Chr(0xF044)), 2dip, 5dip, 40dip, 40dip)
                p.AddView(CreateButton("btnDelete", Chr(0xF00D)), 44dip, 5dip, 40dip, 40dip)
                p.AddView(CreateButton("btnDuplicate",Chr(0xF0C5)), 85dip, 5dip, 40dip, 40dip)
            Next
           
            Log("Index time: " & (DateTime.Now - startTime) & " ms")
        Else
            'no file..do nothing but show the table
            B4XTable1.SetData(Data)
        End If
    Catch
        Log("Error InitTable and Sql" & LastException.Message)
    End Try
End Sub
If you look at For i = 1 To editCol.CellsLayouts.Size - 1 code. It will trigger B4XTable1_DataUpdated event in my project but the example will not.

** Activity (main) Pause, UserClosed = false **
No wakelock.
** Activity (diagreport) Create, isFirst = true **
Class not found: b4a.example.b4xtable, trying: scantech.cardiagnosticpro.b4xtable
Index time: 99 ms
Index time: 10 ms
** Activity (diagreport) Resume **
Class not found: b4a.example.b4xfloattextfield, trying: scantech.cardiagnosticpro.b4xfloattextfield
Error occurred on line: 190 (DiagReport)
java.lang.RuntimeException: Object should first be initialized (View).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:298)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1083)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1030)
at scantech.cardiagnosticpro.b4xtable$ResumableSub_ImplUpdateDataFromQuery.resume(b4xtable.java:2765)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1705)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
B4X:
Private Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim p As B4XView = editCol.CellsLayouts.Get(i + 1)
        p.GetView(1).Visible = B4XTable1.VisibleRowIds.Get(i) > 0
        p.GetView(2).Visible = p.GetView(1).Visible
        p.GetView(3).Visible = p.GetView(1).Visible
    Next
End Sub
 
Top