Android Question Page number in B4XPages

Sergey_New

Well-Known Member
Licensed User
Longtime User
I create a page:
B4X:
Public Page2 As B4XPage2
Page2.Initialize
B4XPages.AddPage("Page 2", Page2)
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
The application uses:
B4X:
#IncludeTitle: False
How can I get the value "Page 2" when opening a page?
I know that this value can be passed to a variable on Page 2, but I would like to get it from Root1.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Page2Layout")
    B4XPages.SetTitle(Me, "Page2 Title")
    Dim PageId As String = B4XPages.GetPageId(Me)
    Log(PageId) ' page 2
End Sub

It will show the Page Id in lowercase.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
It will show the Page Id in lowercase.
Thank you!
It's a pity, but changing the title value doesn't work for me.
It's strange, but in an application with
B4X:
#IncludeTitle: True
the title doesn't change.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Don't confuse with Page Id and Page Title.

To set Page Title, you write as follow:
B4X:
B4XPages.SetTitle(Me, "Page2 Title")
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I recommend to check my 2-pages template.

To use, download and drop this file into B4X Additional Libraries folder.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
It's a pity, but changing the title value doesn't work for me.
This is an incorrect Google translation. It should be like this:
Sorry, but I don't need to change the case of the title.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
So what exactly you want?
There is a string variable on the page being created. When creating the page, it needs to be assigned the text "Page 2" from the string:
B4X:
B4XPages.AddPage("Page 2", Page2)
You need to get:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Page2")
'    Dim tmp As String=?
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
There is a string variable on the page being created.
Both the Page Title and Page Id are String.

You didn't answer my question.
I don't know you don't understand my question or you are not interested to answer.

I think you are still very confuse with the concept of B4XPages.

Assuming your problem is the second one.
Get the value of page id of the B4XPage you want to show
This has nothing to do with:
#IncludeTitle: False

So
When creating the page, it needs to be assigned the text "Page 2" from the string:
B4X:
B4XPages.AddPage("Page 2", Page2)
Yes, you need to give ID to a page when you create a new page.

For example, you have a B4XPage with the name Page2.
You can create more than 1 page from the same Page2 class but you must give each of them different IDs.
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public PageA As Page2
    Public PageB As Page2
End Sub

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "Main Title")
    B4XPages.AddPage("AA", PageA.Initialize)
    B4XPages.AddPage("BB", PageB.Initialize)
End Sub

B4X:
Private Sub BtnShowPageA_Click
    B4XPages.ShowPage("AA")
End Sub

Private Sub BtnShowPageB_Click
    B4XPages.ShowPage("BB")
End Sub

However, if you want to show the title on Page2 base on it's id, you can write as follow:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("Page2")
    Dim PageId As String = B4XPages.GetPageId(Me).ToUpperCase
    B4XPages.SetTitle(Me, "Page " & PageId) ' Title will show "Page AA" or "Page BB"
End Sub

Hope this is what you are looking for.
 

Attachments

  • Example.zip
    17 KB · Views: 32
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
This has nothing to do with:
It seems that translation inaccuracies prevent us from understanding each other.
I am attaching an example project, in which, as it seems to me, you can understand what I need. Comment out the line "Page2.lblHello.Text=str" and try to get the required text in the created page.
I can't explain it better in an unfamiliar language.
Pay attention to the line "#IncludeTitle: False" in the Main Activity.
 

Attachments

  • Test.zip
    4.8 KB · Views: 31
Upvote 0

aeric

Expert
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("page2")
    'lblHello.Text = ?
    Dim PageId As String = B4XPages.GetPageId(Me)
    PageId = PageId.SubString2(0, 1).ToUpperCase & PageId.SubString(1) ' make first letter to uppercase
    lblHello.Text = PageId
End Sub
 

Attachments

  • Test.zip
    14.9 KB · Views: 30
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Sorry to interject, but I think there are some communication snags here.

I looked at the code, and the problem I see is that the page is not yet created when the string is assigned.
Change the .AddPage to B4XPages.AddPageAndCreate(str, Page2).

Then the layout will be loaded and the string assignment will work.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
aeric, thank you! Your example works. The difficulty of the example is that you will have to parse each word in the transmitted text, where there may be capital letters. It is easier to use Page2.lblHello.Text=str
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
aeric, thank you! Your example works. The difficulty of the example is that you will have to parse each word in the transmitted text, where there may be capital letters. It is easier to use Page2.lblHello.Text=str
Don't use page Id for passing values to another page.
Just access the variable or view directly like you access lblHello. This is how B4XPages simplify things.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Please explain how to call a variable and how to access the view directly?
It is what you are doing now.

In B4XPage2, you wrote:
B4X:
Public lblHello As Label

In B4XMainPage, you access it as follow:
B4X:
Page2.lblHello.Text=str

or

if you want to access a variable in another page, you can write like this:

In B4XPage2:
B4X:
Public str As String

In B4XMainPage:
B4X:
Page2.str = "It can be any text"
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…