Android Question B4xPages HideKeyboard

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

In B4A "HideKeyboard" is handled as below.

B4X:
Private Ph As Phone
Private  Display1   As EditText      'In Designer ---  Input Type Decimal numbers
Sub Display1_EnterPressed
    dummytext.RequestFocus
    Ph.HideKeyboard(Activity)
End Sub

In B4XPages "Activity" of course is not valid. How do we close the keyboard?
B4X:
Private Ph As Phone
Private  Display1   As B4XView     'In Designer --- Input Type Decimal numbers
Sub Display1_EnterPressed
    dummytext.RequestFocus
    Ph.HideKeyboard(Activity)
End Sub

Regards Roger
 

LucaMs

Expert
Licensed User
Longtime User
In B4XPages "Activity" of course is not valid
It would be:
B4X:
Ph.HideKeyboard(B4XPages.GetNativeParent(Me))

but:

1 - It is better to use the library IME:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Display1 As EditText
    ' Private dummytext As EditText ' no more needed
    Private IME1 As IME
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    IME1.Initialize("IME1")
End Sub

Sub Display1_EnterPressed
    IME1.HideKeyboard
End Sub

2 - both methods would only work with B4A, of course.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
It would be:
B4X:
Ph.HideKeyboard(B4XPages.GetNativeParent(Me))

but:

1 - It is better to use the library IME:
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Display1 As EditText
    ' Private dummytext As EditText ' no more needed
    Private IME1 As IME
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    IME1.Initialize("IME1")
End Sub

Sub Display1_EnterPressed
    IME1.HideKeyboard
End Sub

2 - both methods would only work with B4A, of course.

Many thanks LucaMs.
Using the IME library looks like a good option, I'll give it a try when I get home.

Regards Roger
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
You don't need to hide the keyboard in EnterPressed. Make sure that Force Done option is selected.

Thanks Erel,
Force Done is already ticked on Display1, which hides the Keyboard, but removing the Focus from Display1 by having "dummytext" request Focus immediately shows the Keyboard again. All looking good using IME. :)

Regards Roger
 
Upvote 0
Top