Usually, there are people who try to focus an object and / or open the keyboard on a specific edittext.
The first time someone is asking for the opposite
Usually, there are people who try to focus an object and / or open the keyboard on a specific edittext.
The first time someone is asking for the opposite
Oh thanks, that's a way. Another way that i'm trying is to make another invisibile edittext, request focus on it, close keyboard and remove edit text. I will test and send the result
This solution is the most correct. Use the Reflector Library
B4X:
Sub NoFocus (EditText1 As EditText)
Dim obj1 As Reflector
obj1.Target = EditText1
obj1.RunMethod2("setFocusable", "False", "java.lang.boolean")
End Sub
Dim tx As EditText
tx.Initialize("")
Activity.AddView(tx,-1,-1,1,1)
In sub that clear focus:
B4X:
Dim im As IME
im.Initialize("")
im.HideKeyboard
Dim reflect As Reflector
For Each v As View In p.GetAllViewsRecursive
If v Is EditText Then
Dim vi As EditText = v
reflect.Target = vi
reflect.RunMethod("clearFocus")
End If
Next
'p is my panel
clearFocus sets the focus back to the first focusable view in activity, so i add an edittext as first view in activity to move focus on it
This solution is the most correct. Use the Reflector Library
B4X:
Sub NoFocus (EditText1 As EditText)
Dim obj1 As Reflector
obj1.Target = EditText1
obj1.RunMethod2("setFocusable", "False", "java.lang.boolean")
End Sub
I understand this thread is old, but I feel it is important to report that once the EditText has been set to non focusable, it becomes impossible to focus it again.
I understand this thread is old, but I feel it is important to report that once the EditText has been set to non focusable, it becomes impossible to focus it again.
Does function does just that, of reactivating the focus by recalling the same method putting True instead of false
If you simply want to temporarily remove the focus and not disable it, use the method recommended in post # 13
I know it's an old thread but it came high up the search and the info might help stop someone else going insane for a few hours...
My similar problem was with EditText getting the focus and opening the soft keyboard when the activity was resumed. This code stopped it.
B4X:
Sub Activity_Resume
Dim obj1 As Reflector
obj1.Target = MyEditText
obj1.RunMethod2("setFocusable", "True", "java.lang.boolean")
obj1.RunMethod2("setFocusableInTouchMode", "True", "java.lang.boolean")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
IME1.HideKeyboard
Dim obj1 As Reflector
obj1.Target = MyEditText
obj1.RunMethod2("setFocusable", "False", "java.lang.boolean")
End Sub