The code below works when I off focus to another textField but not when I just tap anywhere on the screen (which I’d like to trigger the onFocusChanged event). How can I achieve this? I’ll also need to check that the other textfield doesnt’t have focus, because if it does the keyboard should be retained.
usernameET.setOnFocusChangeListener((new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(v == usernameET) {
Log.d(LoginPage.Tag, "keyboardOnTouch");
if (hasFocus)
{
((InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(usernameET,
InputMethodManager.SHOW_FORCED);
}
else {
((InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
usernameET.getWindowToken(), 0);
}
}
}
}));
You can use the onTouchEvent() to hide the Softkeyboard.
Hope this will help.