B4J Question use enter key instead of tab key for swiching next edittext

tango

Active Member
Licensed User
Longtime User
use enter key instead of tab key for swiching next edittext
 

EnriqueGonzalez

Expert
Licensed User
Longtime User
Actually is not that difficult to implement that.

Create the Textfields with the same event name
Add a tag to each textbox with an index
add them to a list

and for the event something like this (not tested)

B4X:
private Sub yourEvent_Action
Dim textbox As TextField = Sender
Dim index As Int = textbox.Tag

If index + 1 < listOfText.Size Then

Dim FutureTextBox As TextField = listOfText.Get(index + 1)

FutureTextBox.RequestFocus

End If

End Sub
 
Upvote 0

tango

Active Member
Licensed User
Longtime User
hi Enrique,
thanks for reply. can we do like this?
activity(keypress ...)
if pressed key enterkey
act as tabkey
....
...
how?
 
Upvote 0

EnriqueGonzalez

Expert
Licensed User
Longtime User
Ey Tango!

Yes.. actually you can, All nodes have a AddEventHandler method for this specific function (not released in B4J), But it is not as useful as you may think, because Every node is responsible for hearing the keys, that means you will need to do it for every textfield you have.

And i must apologize, i do no have the complete solution, i did it once for a Mouse Exit event, Hope someone else can complement it, or you can figure it out.
the solution i gave above is very practical and easy to use.

B4X:
private Sub setHandler(ob As Object,eventName As String,handlerName As String)

asJavaObject(ob).RunMethod(eventName, Array(asJavaObject(ob).CreateEventFromUI("javafx.event.EventHandler",handlerName,False)))

End Sub

private Sub asJavaObject(j As JavaObject) As JavaObject

Return j

End Sub

Sub appstart
setHandler(parentPane,"setOnKeyPressed","textfield_keypressed"

end sub

private Sub textfield_keypressed_Event(MethodName As String, Args() As Object)
'Do stuff here, the args contains the keyEvent that you must declare as a java Object like this:
dim KeyEvent as Javaobject = args(0)

End Sub
 
Upvote 0
Top