Android Question EditText delete focus

Star-Dust

Expert
Licensed User
Longtime User
Call metod RequestFocus another object :p:p:p

Try PanelName.RequestFocus
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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 o_Oo_Oo_Oo_O
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Call metod RequestFocus another object :p:p:p

Try PanelName.RequestFocus
Tried on Button and activity, doesn't work.
and make it invisible :)
Panel? Or edittext? Edit text I need it visibile

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 o_Oo_Oo_Oo_O
i think he wants to lose focus after hes done with the keyboard
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 text
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Only this?
I need to close keyboard when I click out the edit text.

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
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
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


I don't need how to close keyboard, it works for me, i need how to delete focus xD i tried RequestFocus on another view, but doesn't work
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Hi to all! There is a way to delete focus from an edit text (and cursor)?
That'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

IMG_20170504_225214.jpg
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
That'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
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
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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
 
Last edited:
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
I finally found the tips that works for me

In Activity_Create, before load layout:
B4X:
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
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Other little tips, that works for me:
B4X:
Dim t As EditText
    t.Initialize("")
    Activity.AddView(t,-1,-1,0,0)
    t.RequestFocus
    t.RemoveView

This works as clearFocus, focus will jump into first focusable view, so you should add a edit text in activity_create
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
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
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I did try to re-enable focus with the code below, but the EditText would not get focus anymore.

I ended up using the method described by Emme Developer, with an EditText off view I set focus to.

B4X:
    Dim obj1 As Reflector
    obj1.Target = EditText1
    obj1.RunMethod2("setFocusable", "True", "java.lang.boolean")
 
Last edited:
Upvote 0

techgreyeye

Member
Licensed User
Longtime User
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
 
Upvote 0
Top