Android Question Still LostFocus

LucaMs

Expert
Licensed User
Longtime User
I've looked everywhere, on the site and on Web, but I can not find a way to get the LostFocus (HasFocus = False) when the view that gets the focus has not an editable text, such as buttons, imageviews, ...
 

stevel05

Expert
Licensed User
Longtime User
Have you tried the Reflection library and the SetOnFocusListener?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
A button wouldn't normally take the focus, so if you make it focusable, the first click is consumed by the focus.

Can you explain your intended usage, there may be an other way to achieve what you're after.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The feature that I would get is simple, in theory :mad:.

Let's say I have a EditText; the user enters text and then press the OK button.

It is obvious that I could check the contents entered in the EditText inside the btnOK_Click event, but it is just an example to say that when the user presses OK, the event EditText_FocusChanged does not fire.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Where does the Focus go once OK is pressed?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
As thedesolatesoul said, pressing the OK button in an edittext doesn't necessarily move the focus, unless there is another focusable view for it to go to and you haven't set force done on the keyboard.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you want the buttons to be focusable you can set it using JavaObject:

B4X:
DIm JO AS JavaObject = Button1
JO.RunMethod("setFocusable",Array As Object(True))

Or

B4X:
DIm JO AS JavaObject = Button1
JO.RunMethod("setFocusableInTouchMode",Array As Object(True))

In this case, you might as well write:
EditText1_FocusChanged (True)

You'd probably be better off using the TextChanged event
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
1) the button is in the focused state, it can have a different graphic (Which may be the same as pressed by default because buttons are not normally focusable) but you can change it using a statelistdrawable if you really want to.

2) see #4
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try this one.
 

Attachments

  • LMS.zip
    7.2 KB · Views: 272
Upvote 0
Top