B4J Question Find the focussed view in a pane

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have a pane containing four listviews. When I click a button I would like to be able to discover which listview in the pane (if any) has focus. I searched for "find focussed view" and got nothing. I suspect that javaObject might be required. Any help appreciated.

Edit : Maybe I have to track when any of the listboxes becomes the focussed view, as after the button is pressed whichever listbox had focus will have lost it by then!
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Do While True
        Log(GetFocusedView)
        Sleep(1000)
    Loop
End Sub

Private Sub GetFocusedView As B4XView
    Dim frm As Form = B4XPages.GetNativeParent(Me)
    Dim focused As JavaObject = frm.As(JavaObject).GetFieldJO("scene").RunMethod("focusOwnerProperty", Null)
    If focused.IsInitialized Then Return focused.RunMethod("get", Null)
    Return Null
End Sub
 
Upvote 0
Top