Android Question [Solved] CallBack object from inside class [B4XPages]

makis_best

Well-Known Member
Licensed User
Longtime User
Hello.

I have a class with the name Box2.
Inside the class I declare one B4XTable I can't understand what I need to have on callback object so I can make b4xtable to work.

I show you some of my code to help you understand my problem.

B4X:
Sub Class_Globals
    
    Private B4XTable2 As B4XTable
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
'    Create table
    B4XTable2.Initialize(??????, ??????)  -->  What I need to have here?
    B4XTable2.AddColumn("findoc", B4XTable2.COLUMN_TYPE_NUMBERS)
    Dim ItemCode As B4XTableColumn =B4XTable2.AddColumn("Code", B4XTable2.COLUMN_TYPE_TEXT)
    ItemCode.Width = 92dip
    Dim Barcode As B4XTableColumn = B4XTable2.AddColumn("Barcode", B4XTable2.COLUMN_TYPE_TEXT)
    Barcode.Width = 100dip
    Dim item As B4XTableColumn = B4XTable2.AddColumn("Material", B4XTable2.COLUMN_TYPE_TEXT)
    B4XTable2.AddColumn("Ποσότητα", B4XTable2.COLUMN_TYPE_NUMBERS)
    item.Width = 100dip
    Dim Qnt As B4XTableColumn = B4XTable2.AddColumn("Qnt", B4XTable2.COLUMN_TYPE_NUMBERS)
    Qnt.Width = 100dip
    Dim RealQnt As B4XTableColumn = B4XTable2.AddColumn("Pallete", B4XTable2.COLUMN_TYPE_NUMBERS)
    RealQnt.Width = 100dip
    B4XTable2.Refresh
    GetRecordLines("select_Lines", Main.findoc)
    
End Sub

Thank you
 

makis_best

Well-Known Member
Licensed User
Longtime User
In B4XMainPage you can have a button1:
B4X:
Private Sub Button1_Click
    B4XPages.ShowPage("Box2")
End Sub
I don't understand your answer.
My question is what to fill inside B4XTable2.Initialize(??????, ??????) of class when I call class for B4xmainpage or no need to have that line?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have done all that..
My question is how class will return in mainpage the table
In the source code you posted I don't see what you ask and I don't understand.

Anyway, you can add parameters to the Sub Initialize of each class. One of these is often the callback, the calling module/class.


'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

Public Sub Initialize(Callback As Object)
mCallback = Callback ' mCallback is a your class level var
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
I just ask how to do initialize b4xtable inside the class.
The class called from inside b4xmainpage
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The code that you have in #1 won't work if it is in the "Initialize" sub.

Move it to the B4XPage_Created after the loadlayout. The designer will initialize the table.
So don't initialize it again. Omit that line.
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Are you putting a view into a standard class? Usually I only put view inside a custom view class.

If putting a view in a standard class, then I assume:

Public Sub Initialize() should have 3 parameters, callback, event, and a container to put the view in.
Then B4XTable2.Initialize(??????, ??????) should be B4XTable2.Initialize(Me, eventname string used in this class)
The view should be added to the container.

Implement B4XTable2 event subs in this class and these subs should call events from callback, pass Me as callback parameter when make instance of this class.

Update: Tested in B4J using a custom view and in normal UI mode it works.
 
Last edited:
Upvote 0

lucasheer

Active Member
Licensed User
Longtime User
B4XTable2.Initialize(??????, ??????) --> What I need to have here?

The events will be sent to the class that you set the callback to, under the name of the event that you set:

Initialize (Callback as object, EventName as string)
B4X:
B4XTable2.Initialize(Me, "B4XTable2")

Here are possible events you have with B4XTable (They have to be in the same class that you initialized the B4XTable in, or set the callback to):

B4X:
Private Sub B4XTable2_CellClicked (ColumnId As String, RowId As Long)
Private Sub B4XTable2_CellLongClicked (ColumnId As String, RowId As Long)
Private Sub B4XTable2_DataUpdated
Private Sub B4XTable2_HeaderClicked (ColumnId As String)
Private Sub B4XTable2_HeaderLongClicked (ColumnId As String)


Example project:
https://www.b4x.com/android/forum/t...ortable-searchable-customizable-table.102322/
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
Hi makis: Can you please export a simple example to show us how you solved it, because I use B4Xtable a lot and never had to use this line: B4XTable2.Initialize(Me, "B4XTable2") to make it work.
Sure I do... I just was out of town....

my class start like....

B4X:
Sub Class_Globals
    Private B4XTable22 As B4XTable

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize()
'    Create table
    B4XTable22.Initialize(Me, "B4XTable22")
    Dim findocCol As B4XTableColumn = B4XTable22.AddColumn("findoc", B4XTable22.COLUMN_TYPE_NUMBERS)
    findocCol.Width = 70dip

After that all start working fine.
 
Upvote 0
Top