I have an activity with a listview and each row has several editText. It looks like a questionnaire. I have for example the focus on one EditText, then I click on another EditText. At the moment, the keyboard disappear and reappear. It is very irritating.
I use that code to make the keyboard disppear when the user click anywhere else on the activity when he don't want to type. But if the user click on another editText, I would like the keyboard stay.
Someone has an idea if the keyboard is already shown, how to keep it open when I click on a EditText?
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
View w = getCurrentFocus();
if (w instanceof EditText) {
int scrcoords[] = new int[2];
w.getLocationOnScreen(scrcoords);
float x = event.getRawX() + w.getLeft() - scrcoords[0];
float y = event.getRawY() + w.getTop() - scrcoords[1];
if (event.getAction() == MotionEvent.ACTION_UP && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom()) ) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
return super.dispatchTouchEvent(event);
}