Android Question Cross platform Editable B4XTable + Form Example

Mitesh_Shah

Member
Licensed User
Longtime User
Hi
i am working on b4a projects, its based on >> https://www.b4x.com/android/forum/threads/b4x-cross-platform-editable-b4xtable-form-example.104766/

i am try to add time-24 hour format, also update json file using form builder

also change in code


Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("1")

'If LoadLayout = ("1") Then
'Root.LoadLayout("2")
'Root.LoadLayout("3")
xui.SetDataFolder("TableAndForms")
editCol = B4XTable1.AddColumn("Edit", B4XTable1.COLUMN_TYPE_TEXT)
editCol.Sortable = True
editCol.Width = 127dip
B4XTable1.RowHeight = 50dip
B4XTable1.NumberOfFrozenColumns = 1

'// B4XTable1.AddColumn("Type", B4XTable1.COLUMN_TYPE_TEXT)
'// B4XTable1.AddColumn("Name", B4XTable1.COLUMN_TYPE_TEXT)
'// B4XTable1.AddColumn("Birth Date", B4XTable1.COLUMN_TYPE_DATE)
'// B4XTable1.AddColumn("Sex", B4XTable1.COLUMN_TYPE_TEXT)

B4XTable1.AddColumn("Mode", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Day", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Time", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Bell_Typ", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("M_No", B4XTable1.COLUMN_TYPE_TEXT)

LoadData
PrefDialog.Initialize(Root, "ADD Bell Time", 300dip, 300dip)
PrefDialog.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
'PrefDialog.SetOptions("Type", File.ReadList(File.DirAssets, "animals.txt"))
'PrefDialog.SearchTemplate.MaxNumberOfItemsToShow = 300
B4XTable1.MaximumRowsPerPage = 20
B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)

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
End Sub

Private Sub ShowDialog(Item As Map, RowId As Long)
Wait For (PrefDialog.ShowDialog(Item, "OK", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
Dim params As List
params.Initialize
params.AddAll(Array(Item.Get("Mode"), Item.Get("Day"), Item.Get("Time"), Item.Get("Bell_Typ"), Item.Get("Mp3_No"))) '// keys based on the template json file
If RowId = 0 Then 'new row
B4XTable1.sql1.ExecNonQuery2($"INSERT INTO data VALUES("", ?, ?, ?, ?, ?)"$, params)
B4XTable1.ClearDataView
Else
params.Add(RowId)
'first column is c0. We skip it as this is the "edit" column
B4XTable1.sql1.ExecNonQuery2("UPDATE data SET c1 = ?, c2 = ?, c3 = ?, c4 = ?, c5 = ? WHERE rowid = ?", params)
B4XTable1.Refresh
End If
End If
End Sub

but getting some error's

here attached images
 

Attachments

  • forms_table Error List.jpg
    forms_table Error List.jpg
    293 KB · Views: 90
  • forms_table.jpg
    forms_table.jpg
    89.2 KB · Views: 86
Last edited:

josejad

Expert
Licensed User
Longtime User
If you upload a small project showing the problem, is easier for us to help you
 
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
b4a:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("1")
 
    'If LoadLayout = ("1") Then
    'Root.LoadLayout("2")
    'Root.LoadLayout("3")
    xui.SetDataFolder("TableAndForms")
    editCol = B4XTable1.AddColumn("Edit", B4XTable1.COLUMN_TYPE_TEXT)
    editCol.Sortable = True
    editCol.Width = 127dip
    B4XTable1.RowHeight = 50dip
    B4XTable1.NumberOfFrozenColumns = 1

    '// B4XTable1.AddColumn("Type", B4XTable1.COLUMN_TYPE_TEXT)
    '// B4XTable1.AddColumn("Name", B4XTable1.COLUMN_TYPE_TEXT)
    '// B4XTable1.AddColumn("Birth Date", B4XTable1.COLUMN_TYPE_DATE)
    '// B4XTable1.AddColumn("Sex", B4XTable1.COLUMN_TYPE_TEXT)

    B4XTable1.AddColumn("Mode", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Day", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Time", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Bell_Typ", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("M_No", B4XTable1.COLUMN_TYPE_TEXT)
 
    LoadData
    PrefDialog.Initialize(Root, "ADD Bell Time", 300dip, 300dip)
    PrefDialog.LoadFromJson(File.ReadString(File.DirAssets, "template.json"))
    'PrefDialog.SetOptions("Type", File.ReadList(File.DirAssets, "animals.txt"))
    'PrefDialog.SearchTemplate.MaxNumberOfItemsToShow = 300
    B4XTable1.MaximumRowsPerPage = 20
    B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
 
    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
End Sub

Private Sub ShowDialog(Item As Map, RowId As Long)
    Wait For (PrefDialog.ShowDialog(Item, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim params As List
        params.Initialize
        params.AddAll(Array(Item.Get("Mode"), Item.Get("Day"), Item.Get("Time"), Item.Get("Bell_Typ"), Item.Get("Mp3_No")))    '// keys based on the template json file
        If RowId = 0 Then 'new row
            B4XTable1.sql1.ExecNonQuery2($"INSERT INTO data VALUES("", ?, ?, ?, ?, ?)"$, params)
            B4XTable1.ClearDataView
        Else
            params.Add(RowId)
            'first column is c0. We skip it as this is the "edit" column
            B4XTable1.sql1.ExecNonQuery2("UPDATE data SET c1 = ?, c2 = ?, c3 = ?, c4 = ?, c5 = ? WHERE rowid = ?", params)
            B4XTable1.Refresh
        End If
    End If
End Sub



but getting some error's

Error:
Logger connected to: emulator-5554
--------- beginning of system
--------- beginning of crash
--------- beginning of system
--------- beginning of crash
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
preferencesdialog_filldata (java line: 1006)
java.lang.ClassCastException: java.lang.String cannot be cast to b4a.example.dateutils$_period
    at b4a.example.preferencesdialog._filldata(preferencesdialog.java:1006)
    at b4a.example.preferencesdialog$ResumableSub_ShowDialog.resume(preferencesdialog.java:1984)
    at b4a.example.preferencesdialog._showdialog(preferencesdialog.java:1819)
    at b4a.example.b4xmainpage$ResumableSub_ShowDialog.resume(b4xmainpage.java:395)
    at b4a.example.b4xmainpage._showdialog(b4xmainpage.java:369)
    at b4a.example.b4xmainpage._btnduplicate_click(b4xmainpage.java:220)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6597)
    at android.view.View.performClickInternal(View.java:6574)
    at android.view.View.access$3100(View.java:778)
    at android.view.View$PerformClick.run(View.java:25885)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 

Attachments

  • forms_table.jpg
    forms_table.jpg
    89.2 KB · Views: 61
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
this Line is working perfect for whan use date

b4a:
B4XTable1.AddColumn("Birth Date", B4XTable1.COLUMN_TYPE_DATE)

but, modified for time

b4a:
B4XTable1.AddColumn("Time", B4XTable1.COLUMN_TYPE_TEXT)
 
Upvote 0
Top