InputDialog question (and/or wish)

boten

Active Member
Licensed User
Longtime User
When InputDialog is shown, the keyboard is opened only when the text input field is clicked, although this field is the only one avaiable for input and it already has the focus.

Is it possible to "automatically" open the keyboard once the the InputDialog is shown?
 

TomA

Active Member
Licensed User
Longtime User
Basically, the answer is 'Yes'. But I would suggest that the app should first ensure there is no physical keyboard on the device.
My "Hunt the Wumpus" program uses the following code:

B4X:
Sub Globals
        Dim TextEdit As EditText  ' An edit text field

        Dim IME As IME
        Dim ref As Reflector
End Sub

Then in the Activity_Create, the first time through

B4X:
KeyboardPresent = HardwareKeyboardPresent

where KeyboardPresent is defined as a boolean under Process_Globals

The function HardwareKeyboardPresent is

B4X:
Sub HardwareKeyboardPresent As Boolean
    ref.Target = ref.GetContext
    ref.Target = ref.RunMethod("getResources")
    ref.Target = ref.RunMethod("getConfiguration")
    Dim keyboard As Int = ref.GetField("keyboard")
    Return keyboard <> 1 'KEYBOARD_NOKEYS - return true if keyboard, else      return false 
End Sub

Then, when the text edit field gets the focus, open the keyboard with this code

B4X:
     TextEdit.RequestFocus
     If KeyboardPresent = False Then
           IME.ShowKeyboard (TextEdit)
     End If

Finally, when the text edit no longer has the focus, or the keyboard is no longer needed, you can ensure it closes with

B4X:
     If KeyboardPresent = False Then
          IME.HideKeyboard
         End If

This works well in my app.

Tom Aman
 
Last edited:
Upvote 0
Top