B4J Question In TextArea nodes, pressing TAB doesn't move to the next node??

MegatenFreak

Active Member
Licensed User
Hi. In my app's forms I need to allow the user quick passage between fields by pressing TAB. It works fine with all nodes except TextArea, in which pressing TAB only adds tab spaces inside the text box. How can I make it so TAB moves to the next node?
I searched around in Java forums and there are some complex solutions that involve defining events and stuff. I was wondering if there was an easier way.
Thanks a lot in advance.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
No simple solution. It does require intercepting the event.



B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim r As Reflector
    For Each v As B4XView In Root.GetAllViewsRecursive
        If v Is TextArea Then
            r.Target = v
            r.AddEventFilter("keypressed", "javafx.scene.input.KeyEvent.ANY")
        End If
    Next
End Sub


Sub KeyPressed_Filter (e As Event)
    Dim jo As JavaObject = e
    Log(e)
    Dim eventType As String = jo.RunMethod("getEventType", Null)
    Dim code As String = jo.RunMethod("getCode", Null)
    If code = "TAB" And eventType = "KEY_PRESSED" Then
        Dim v As B4XView = jo.RunMethod("getSource", Null)
        For i = 0 To Root.NumberOfViews - 1
            If Root.GetView(i) = v Then
                Dim NextView As B4XView = Root.GetView((i + 1) Mod Root.NumberOfViews)
                NextView.RequestFocus
                Exit
            End If
        Next
        e.Consume
    End If
End Sub

Note that there is an assumption here that the TextAreas parent is the Root panel.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…