B4J Question B4XPages App - Global TextChanged

mmanso

Active Member
Licensed User
Longtime User
Hi all,

I'm writing a B4XPages application that one of the things it does is reading keys from several devices (barcode readers, keyboard, etc).

I've multiple pages in the application.

Is there any way to register a global TextChanged or KeyPress that captures the key presses and then in any page I am I can process them without trying to register a TextChanged in every pages?

Thanks in advance.
 

Gianni M

Well-Known Member
Licensed User
Longtime User
i have solved with a Custom View; a simple Custom View with only TextField and the code checks for events;
maybe with B4XPages there is another solution ?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
In B4XPages events are fired in the UI context (in B4J page=form) in which the view was created.

If you want to handle all similar events in the B4XMainPage then you can delegate the handling with 3 lines of code (2 are generated by the designer).

B4X:
'In the page where the UI view was created (initialized)
Private Sub TextField1_TextChanged (Old As String, New As String)
    B4XPages.MainPage.TextChangedHandler(Old, New)
End Sub

'put the following in B4XMainPage
Public Sub TextChangedHandler(old As String, new As String)
    Log(old & TAB & new)
    'etc
End Sub
 
Upvote 0

mmanso

Active Member
Licensed User
Longtime User
Hi there,

I've tried that tecnique but the problem I'm having is that it works ok in the beggining. I've two pages and each has a TextField which patures the TextChanged event. But as soon as I do:

B4X:
B4XPages.ShowPageAndRemovePreviousPages("page2")

I go to page two, a nd the TextChanged from the EditText in page2 works ok. After that, when I do:

B4X:
B4XPages.ShowPageAndRemovePreviousPages("page1")

back to page 1, the TextChanged don't get captured and if I go back to page two, the event don't work also.

Any clue why?

Thanks.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Do you need to remove previous page? ShowPageAndRemovePreviousPages removes the previous page, in this case the page with the delegated event handler.
ShowPage will work in almost all cases. Removal can be useful, but only when the page will not be used again, for example a login page.

[Sorry for the slow response, we seem to be in different time zones]
 
Upvote 0
Top