I need to catch when an EditText
loses focus, I've searched other questions but I didn't find an answer.
I used OnFocusChangeListener
like this
OnFocusChangeListener foco = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
}
};
But, it doesn't work for me.
Have your
Activity
implementOnFocusChangeListener()
if you want a factorized use of this interface, example:In your
OnCreate
you can add a listener for example:then android studio will prompt you to add the method from the interface, accept it... it will be like:
and as you've got a factorized code, you'll just have to do that:
anything you code in the
!hasFocus
is for the behavior of the item that loses focus, that should do the trick! But beware that in such state, the change of focus might overwrite the user's entries!Implement
onFocusChange
ofsetOnFocusChangeListener
and there's a boolean parameter for hasFocus. When this is false, you've lost focus to another control.Its Working Properly