Android Question Changing label value from different B4Xpages

Sganga61

Member
Licensed User
Longtime User
Hi everybody
I have a question: I'm trying to read/change a label text (a label fixed by designer) from a second B4Xpage.

Here is the steps I need:
1) Read the original label text from second B4Xpage
2) Add at the readed text the string "...read" (the routine is on the second B4Xpage)
3) Finally rewrite the label with the new text "original value ...read" and return to the B4Xmainpage

Jumping from different pages I can't read label value, edittext value and control any other view

I'm very confused...
Any idea?
 

Sganga61

Member
Licensed User
Longtime User
Try it with:
B4X:
 B4XPages.AddPageAndCreate("COMMON", COMMON)
Make the label public and call it from your 2. page
Your 2. page code:
B4X:
B4XPages.MainPage.Label1.Text = B4XPages.MainPage.Label1.Text & " read"
B4XPages.ClosePage(Me)
Hi Alexander
thanks for your answer but I can't able to use your suggestion.
I try to explain better.

I have two B4xpages + Main.
The first page is B4XMainPage created by main the second is named COMMON (containing all the common routines I use in my different projects).

In the Main page I define in the PROCESS_GLOBAL all the variables (int, string & boolean)

The B4xMainPage is created by main:
- Dim pm As B4XPagesManager
- pm.Initialize(Activity)
- and Defining in the Class_Global of B4XMainPage all the view & public COMMON as MYCOMMON (mycommon is the name of page)

The COMMON Page is created B4XMainPage by:
- COMMON.Initialize
- B4XPages.AddPage("COMMON", COMMON)
- and Defining in the Class_Global of COMMON: public MACHINE as B4XMainPage

Sometime COMMON need to update labels (eg: MACHINE.SERIAL_NUMBER_ENTRY.TEXT = "not present") where SERIAL_NUMBER is an EditText view

Trying to do that I get this error: java.lang.NullPointerException: null receiver

I forget some initialization?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I'm not home, so i cant test it, but i see the problem.

in the "GMS_COMMON" you do the following:
B4X:
Public Sub Class_Globals
    Public Root                         As B4XView
    Public xui                             As XUI
    
    Public MACHINE                        As B4XMainPage    'no don't do this
End Sub
You declare the B4XMainPage without ever assigning a value to it.

You can call the B4XMainPage simply following: B4XPages.MainPage.SERIAL_NUMBER

Other pages, which are not the B4XMainPage, you can simply call like this: B4XPages.MainPage.COMMON.SERIAL_NUMBER_Enterpressed
 
Upvote 0

Sganga61

Member
Licensed User
Longtime User
I'm not home, so i cant test it, but i see the problem.

in the "GMS_COMMON" you do the following:
B4X:
Public Sub Class_Globals
    Public Root                         As B4XView
    Public xui                             As XUI
   
    Public MACHINE                        As B4XMainPage    'no don't do this
End Sub
You declare the B4XMainPage without ever assigning a value to it.

You can call the B4XMainPage simply following: B4XPages.MainPage.SERIAL_NUMBER

Other pages, which are not the B4XMainPage, you can simply call like this: B4XPages.MainPage.COMMON.SERIAL_NUMBER_Enterpressed
WOW ! Yes! now all works perfectly!
Thank you so much Alexander
 
Upvote 0
Top