First, I don’t know what’s the key code for the Return key or Backspace the one that has a line on the Android keyboard.
Secondly I have multiple edittext fields on the screen and I want each one to resign the keyboard when the user hit that Return key.
imm= (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
public void onClick(View v) {
int flag;
flag=v.getId();
// keycode for return
if(v.getId()==XX) {
imm.hideSoftInputFromWindow(YYY.getWindowToken(), 0);
}
XX is the keycode for that Return key and YYY is what I should fill in. I would like YYY generic that’s applying to all the edittext fields in the program
I’m not sure why you are trying to handle this in an
onClickmethod. The right way, I think, is to callsetOnKeyListener()for each EditText view and in yourOnKeyListener, you can do this:A single instance of
OnKeyListenercan be used for all EditText views (any view at all, actually) where you want this behavior.