Ok everyone knows that to hide a keyboard you need to implement:
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hi
I find the accepted answer a bit complicated.
Here's my solution. Add an OnTouchListener to your main layout, ie.:
findViewById(R.id.mainLayout).setOnTouchListener(this)
and put the following code in the onTouch method.
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
This way you don't have to iterate over all views.