I have one screen in which there is an alert box.
In this alert box there is one spinner control and two text fields.
Problem is when I select any text field it opens keyboard but when I click on outside textfield, I need to hide keyboard, I have used method given below to hide keyboard but it doesn't hide keyboard whether it is working without alert box.
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
View view = getCurrentFocus();
boolean ret = super.dispatchTouchEvent(event);
if (view instanceof EditText) {
View w = getCurrentFocus();
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 ret;
}
Can anybody please tell me why it is creating issue with alert box only.
Please help me.