2013-04-04 69 views
1

我想在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(); 
       } 
      } 
     }); 

加入什麼包做這個任務,或給一些想法提前

感謝

+0

什麼是錯誤/錯誤? – Tushar 2013-04-04 06:04:24

+0

AddTypePressHandler(new KeyDownHandler(){})未定義爲類型EditText – 2013-04-04 06:07:00

+0

KeyDownHandler無法解析爲類型 – 2013-04-04 06:07:17

回答

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; 
     } 
    });