Hi to all! There is a way to delete focus from an edit text (and cursor)?
Tried on Button and activity, doesn't work.Call metod RequestFocus another object
Try PanelName.RequestFocus
Panel? Or edittext? Edit text I need it visibileand make it invisible
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
Yes ronell is right, I need to close keyboard when I click out the edit text. I got it using one, but the cursor remain on edit texti think he wants to lose focus after hes done with the keyboard
I need to close keyboard when I click out the edit text.
Sub CloseKeyboard
Dim Ph As Phone
Ph.HideKeyboard(Activity)
End Sub
Sub Activity_Create(FirstTime As Boolean)
CloseKey(Panel2)
End Sub
Sub CloseKey(V As View)
Dim I As IME
I.Initialize("Ime")
I.HideKeyboard
End Sub
Only this?
Try this
B4X:Sub CloseKeyboard Dim Ph As Phone Ph.HideKeyboard(Activity) End Sub
Or use IME Library
B4X:Sub Activity_Create(FirstTime As Boolean) CloseKey(Panel2) End Sub Sub CloseKey(V As View) Dim I As IME I.Initialize("Ime") I.HideKeyboard End Sub
That's an annoying behaviour for which I would also like to know the answerHi to all! There is a way to delete focus from an edit text (and cursor)?
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 resultThat's an annoying behaviour for which I would also like to know the answer
Simply disable the edittext. The content will be shown in gray and not focused. I decided to use this approach after facing the same problem
If you need to edit it, place a button beside to enable the edittext again
View attachment 55474
Dim tx As EditText
tx.Initialize("")
Activity.AddView(tx,-1,-1,1,1)
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
Dim t As EditText
t.Initialize("")
Activity.AddView(t,-1,-1,0,0)
t.RequestFocus
t.RemoveView
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
Does function does just that, of reactivating the focus by recalling the same method putting True instead of falseI 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.
Dim obj1 As Reflector
obj1.Target = EditText1
obj1.RunMethod2("setFocusable", "True", "java.lang.boolean")
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