Android Question How to use a B4XTable from other B4XPage?

pliroforikos

Active Member
Licensed User
Hi everyone

I have an app with several B4XPages. Every B4Xpage shows data from different tables of a database from web into B4XTables.

My question is this: Can i use a B4XTable from (for example) B4XPage1 to B4XPage2 without creating new B4XTable or downloading data from database.

In B4XPage2 I made a form with VD with a panel (with name panel1) and inside a B4XTable named B4XTable1 (the same name as B4XPage1)
The code bellow is what i did to B4XPage2

B4X:
    Private B4XPp1 As B4XPage1
    B4XPp1.Initialize

and when i hit the button btnInsert i want to show panel1 with B4XTable from B4XPage1 and also later i want to customize display with .CreateDataView.
So:
B4X:
Sub btnInsert_Click
    panel1.Visible = True

' And now i am stuck!!!

End Sub

I will be greatfull with any advice.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can i use a B4XTable from (for example) B4XPage1 to B4XPage2 without creating new B4XTable or downloading data from database.
Yes.

B4X:
Dim t As B4XTable = B4XPage8.Table1
t.mBase.RemoveViewFromParent
Root.AddView(t.mBase, 0, 0, Root.Width, Root.Height)
 
Last edited:
Upvote 0

pliroforikos

Active Member
Licensed User
Thank you very much but forgive my ignorance as i don't understand how to use it.
so 3 lines of code and 4 questions!

1. The
B4X:
t.mBase.RemoveFromParent

maybe is
B4X:
t.mBase.RemoveRemoveViewFromParent

I cant find RemoveFromParent

2.
Do i have to make a variable mBase as B4XView in B4XPage2 ?


3. What aboout Root is the same Root of B4XPage2 ?

4.
When i am compiling the code it shows:
Root.AddView(t, 0, 0, Root.Width, Root.Heigh)
src\b4a\mySxoleiov2\b4xpagemylessons.java:734: error: incompatible types: b4xtable cannot be converted to View
Maybe i have to use panel not B4XTable in AddView?

thank you again
 
Last edited:
Upvote 0

pliroforikos

Active Member
Licensed User
Thank you, in
B4X:
t.mBase.RemoveViewFromParent

shows
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.B4XViewWrapper.RemoveViewFromParent()' on a null object reference

any idea?
 
Last edited:
Upvote 0

pliroforikos

Active Member
Licensed User
Trying to figure out how it is working i made a small project with this problem. If anyone can help is welcome!
 

Attachments

  • B4XpageTable.zip
    14.9 KB · Views: 104
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is here:
B4X:
Dim page1 As B4XPage1
    page1.Initialize
You should never initialize B4XPages yourself.
You have created a new B4XPage1 which has nothing to do with the "real" B4XPage1.

There are many ways to access other pages, here is one:
B4X:
'B4XMainPage:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public pg1 As B4XPage1 '<-- make public
    Private pg2 As B4Xpage2

End Sub

B4XPage2:
B4X:
Dim t As B4XTable = B4XPages.MainPage.pg1.B4XTable1
t.mBase.RemoveViewFromParent
Root.AddView(t.mBase, 0, 0, Root.Width, Root.Height)

Important tip:
Your code will crash if the user goes to page2 before showing page1. There is a simple solution:
B4X:
B4XPages.AddPageAndCreate("page1", pg1) 'change AddPage
This way page1 will be created immediately when the app starts.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…