如何在按下一行键时添加特殊字符?

时间:2013-04-04 06:03:33

标签: android keyboard

我想在android mobile中按下nextline按钮(键)时添加一个特殊字符。

Plz帮我处理Android 2.2键盘。

我试图使用此代码,但它不支持我......

etDetail.addKeyPressHandler(new KeyDownHandler() {
        public void onKeyPress(KeyPressEvent event) {
              int charCode = event.getUnicodeCharCode();
              if (charCode == 0) {
                // it's probably Firefox
                int keyCode = event.getNativeEvent().getKeyCode();
                // beware! keyCode=40 means "down arrow", while charCode=40 means '('
                // always check the keyCode against a list of "known to be buggy" codes!
                if (keyCode == KeyCodes.KEY_ENTER) {
                  doOnEnterKeyPressed();
                }
              } else if (charCode == 13) {
                doOnEnterKeyPressed();
              }  
            }
        });

添加了哪些包来执行此任务或提供一些想法

提前致谢

1 个答案:

答案 0 :(得分:2)

请试试这个。我希望这段代码片段可以帮助您

editText.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {


            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {

                doOnEnterKeyPressed();

            }

            return true;
        }
    });