Android Question Using real wired Keyboard and Enter Key to change between Edit Text

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi there, I am using those android boxes in a setup with monitor, keyboard and mouse for data entry.

The problem is that I cant make the ENTER key to work correctly as a way to change between edit boxes

Tried many suggestions the last one I was doing is this:

B4X:
Sub EditTextPreCadastroComanda_EnterPressed
    Sleep(0)
    EditTextPreCadastroNome.RequestFocus
End Sub
Sub EditTextPreCadastroCPF_EnterPressed
    Sleep(0)
    CallSubDelayed(Me, EditText_EnterPressed)
End Sub
Sub EditTextPreCadastroNome_EnterPressed
    Sleep(0)
    EditTextPreCadastroRG.RequestFocus
End Sub
Sub EditTextPreCadastroDtNasc_EnterPressed
    Sleep(0)
    EditTextPreCadastroCelular.RequestFocus
End Sub
Sub EditTextPreCadastroCelular_EnterPressed
    Sleep(0)
    EditTextPreCadastroProduto.RequestFocus
End Sub

I have also used this one:
B4X:
Sub EditText_EnterPressed
    Dim currentView, nextView As View
    currentView = Sender
    nextView = currentView.Tag
    If nextView.IsInitialized Then
          If Not(nextView.RequestFocus) Then 
            nextView.RequestFocus
        End If
    Else
'        hidekeyboard
    End If
End Sub

In conjunction with the tags holding the next edit object.

In all the cases the problem is that when you hit ENTER in the keyboard (either enter keys) the cursor jumps always 2 edit boxes.

When you are in the Editbox1 and hit enter, you got in the _enterpressed of the Editbox, and the requestfocus for the editbox2 is executed, it changes to it, then the enter is virtually hit again, then it get to the _enterpressed of editbox2 and it executes the requestfocus for the editbox3... where it stops. It is always jumping one editbox.

How can I stop this behavior?

Thanks
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Check B4XPreferencesDialog. This is the best solution for forms implementation.

Another option is to use B4XFloatTextField and set the NextField property. It will take care of not hiding the keyboard and moving the focus correctly.

The last and not recommended option is to implement it yourself with IME.AddHandleActionEvent.
 
Upvote 0
Top