I have made a FragmentActivity. Some Fragments include an EditText
.
I would like, when the Soft Input Keyboard is up and a MotionEvent
happens - except the Event of clicking inside the EditText - the Soft Input to hide. Until now I wrote this code in my MainActivity:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
InputMethodManager im = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
return super.dispatchTouchEvent(ev);
}
It seems to work. But when I click inside the EditText, it hides and it comes up again. I wouldn't like this to happen. In this case I want the Keyboard just to remain on the screen.
Is there any way to disable somehow the
dispatchTouchEvent()
when I click at an EditText inside of a Fragment?Is there any way to detect the click event of an EditText inside of
dispatchTouchEvent()
and make a condition there, that disables the hiding of the soft input?