Android Question EditText_FocusChanged not fired after button clicked

toby

Well-Known Member
Licensed User
Longtime User
I have simple test app (attached) with 3 views (2 EditText and 1 button). I want to save EditText2's change, all at once after editing is completed, so I thought FocusChanged event is better than TextChanged event which is fired for every letter entered or deleted.

After entering some text at EditText2 field, If I click on EditText1, EditText2_FocusChanged would be fired as expected. However if I click Button1 instead of EditText1, the event in question wouldn't be fired.

Did I miss anything? Is there a workaround?

Thanks in advance for your helps!
 

Attachments

  • FocusChanged.zip
    9.2 KB · Views: 239

LucaMs

Expert
Licensed User
Longtime User
It happens because Buttons are not "focusable" by default.

Use this method (select the Reflection library):
B4X:
Sub SetFocusable(Vw As View, Focusable As Boolean)
    Dim objRefl As Reflector
    objRefl.Target = Vw
    objRefl.RunMethod2("setFocusable", Focusable, "java.lang.boolean")
    objRefl.RunMethod2("setFocusableInTouchMode", Focusable, "java.lang.boolean")
End Sub

Call it after Activity.Loadlayout:
SetFocusable(Button1, True)
 
Upvote 0
Top