I am trying to close the keyboard when the focus of EditText
has been lost. And I use this code for that
edt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
InputMethodManager imm = (InputMethodManager) getBaseContext().getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
Log.d(TAG, "edt focus lost");
}
if (hasFocus)
Log.d(TAG, "edt has focus");
}
});
When I touch it, I immediately get the focus. But I don't lose focus until I leave the screen.
I tried opening other Dialogs
on the page, touching other Views
with their own listeners, but "focus lost" message is not fired before I leave the screen.
Why is this happening?