2013年10月14日 星期一
當按下enter時收起鍵盤
EditText nameEditText = (EditText)this.findViewById(R.id.editBasicNameEditText);
OnKeyListener keyboardListener = new OnKeyListener()
{
/**
* This listens for the user to press the enter button on
* the keyboard and then hides the virtual keyboard
*/
public boolean onKey(View arg0, int arg1, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ( (event.getAction() == KeyEvent.ACTION_DOWN ) &&
(arg1 == KeyEvent.KEYCODE_ENTER) )
{
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
return true;
}
return false;
}
} ;
nameEditText.setOnKeyListener(keyboardListener);
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言