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
Try this one:

It makes the Activity's parent view focusable so that the edittext loses it's focus when clearFocus is called.

Tags: clear remove Focus Edittext
 

Attachments

  • LMS2.zip
    7.6 KB · Views: 321
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
No, Panel1 covers the whole layout, all other views should be on the activity.

If you can't get it to work, let me know and I'll create the layout on 3.2
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You're welcome.

The only problem with it I can see is that if the edittext has focus and you touch the edittext again, it loses focus and gets it straight back again. So if you are triggering something from the hasfocus sub, it could get triggered twice, but I'm sure you can work around that.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User


it would require a "hole" in the panel, or the ability to check the coordinates x, y by comparing them with the size and location of the EditText
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, or you could put any edittexts on the panel.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
[Tutorial] "How to emulate Lost Focus events"
That will have to wait for a while, but I'll tag the post and it can be found.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User


The solution "bring to front" works but only for a single view, unfortunately
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try putting the edittexts directly onto the panel.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Try putting the edittexts directly onto the panel.


The problem was that the edittex received the focus twice, once with False and the second with True (or vice versa?).

If I put all the EditText in the panel, I do not solve the problem of LostFocus.

I'll have to force the user (programmer) to use a global variable of type MyCustomView and set it in the FocusChanged.

In the end, it will be used by a programmer, not a normal user.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…