I have an EditText called myTextview. I want the soft keyboard to show when I click on the EditText but then dismiss if I click outside of
Maybe a little bit easier:
Set a focusChangedListener on your edit text and then just hide the keyboard if you don't have focus.
yourEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
hideKeyboard();
}
}
});
private void hideKeyboard() {
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
}