Android Question Change in Oreo

MAGAREY

Member
Licensed User
Longtime User
hi everyone!
I have a project in which I use the following code to detect when you have the focus or not on a button. but in android oreo never triggers the routine, is there any change in this version?

B4X:
Sub SetUpOnFocusListener(Button As Button, EventName As String)
    FocusButton(Button) 'This will let us focus the button.
    Dim JO As JavaObject = Button
    Dim event As Object = JO.CreateEvent("android.view.View.OnFocusChangeListener",EventName,False)
    JO.RunMethod("setOnFocusChangeListener",Array As Object(event))
End Sub
 

MAGAREY

Member
Licensed User
Longtime User
What are you using it for? Are you using a connected keyboard?
yes, im using a connected keyboard ,the problem is when I'm navigating with the arrows, the routine that was created with the SetUpOnFocusListener does not trigger and does not create the white frame on the button that is in focus
 
Upvote 0

MAGAREY

Member
Licensed User
Longtime User
i do make foucusable i use this code
B4X:
Sub FocusButton(Button As Button)
    Dim JO As JavaObject = Button
    JO.RunMethod("setFocusable",Array As Object(True))
    JO.RunMethod("setFocusableInTouchMode",Array As Object(True))
    Button.RequestFocus
End Sub

the focus
Sounds like the focus hasn't changed.
apparently the focus change is done because it allows me to click on the following buttons (without creating the white frame) but it does not trigger the setOnFocusChangeListener that was created,
 
Upvote 0

MAGAREY

Member
Licensed User
Longtime User
Could you check this example? try changing what you suggested but the problem continues.
 

Attachments

  • example.zip
    130.6 KB · Views: 332
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code works properly on Android 9:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim et1, et2 As EditText
   et1.Initialize("")
   et2.Initialize("")
   Activity.AddView(et1, 0, 0, 100dip, 50dip)
   Activity.AddView(et2, 0, 100dip, 100dip, 50dip)
   SetUpOnFocusListener2(et1, "et1")
   SetUpOnFocusListener2(et2, "et2")
End Sub

Sub SetUpOnFocusListener2(v As View, EventName As String)
   Dim JO As JavaObject = v
   JO.RunMethod("setFocusable",Array As Object(True))
   Dim event As Object = JO.CreateEventFromUI("android.view.View.OnFocusChangeListener",EventName,False)
   JO.RunMethod("setOnFocusChangeListener",Array As Object(event))
End Sub

Sub et1_Event (MethodName As String, Args() As Object) As Object
   Log(MethodName)
   Return Null
End Sub

Sub et2_Event (MethodName As String, Args() As Object) As Object
   Log(MethodName)
   Return Null
End Sub

I guess that the problem you encounter is not related to the listener but rather to the focus behavior itself.
 
Upvote 0
Top