Android Question EditText1_FocusChanged

WDK

Member
Licensed User
I am trying to hide my banner when the edittext1 has focus and show my banner on end focus of edittext1. I get a true in the HasFocus boolean, but never a false. How can I determine if my edittext1 no longer has focus?

Sub Activity_Create(FirstTime As Boolean)
EditText1.InputType = EditText1.INPUT_TYPE_DECIMAL_NUMBERS
End Sub

Sub EditText1_FocusChanged (HasFocus As Boolean)
ToastMessageShow(HasFocus,True)
if HasFocus = True then
Appodeal2.hide(Appodeal2.BANNER_BOTTOM)
else
Appodeal2.show(Appodeal2.BANNER_BOTTOM)
end if
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
Most views never capture the focus.
This is what I thought to answer, yesterday, adding also that you can make other views "focusable", using the reflection and the setFocusable method, but I tried this on a button and it changes its appearance (I have not investigated further :)).

B4X:
Sub SetFocusable(Vw As View, Focusable As Boolean)
    Dim R As Reflector
    R.Target = Vw
    R.RunMethod2("setFocusable", Focusable, "java.lang.boolean")
    R.RunMethod2("setFocusableInTouchMode", Focusable, "java.lang.boolean")
End Sub

BTW, without setFocusableInTouchMode, the method does not seem to work, at least when applied to a button.
 
Upvote 0
Top