How can I convert a key code into a char or string?

后端 未结 6 1447
无人共我
无人共我 2020-12-11 14:46

How to convert the keycode into char or string??

Here is the example code:

public boolean onK         


        
相关标签:
6条回答
  • 2020-12-11 15:23

    Tod answer is almost complete, but when you want to settext of an edittext with this eventcode you should to add a little thing:

    sample_et.setText((char)event.getUnicodeChar()+"");
    
    0 讨论(0)
  • 2020-12-11 15:26
    char unicodeChar = (char)event.getUnicodeChar();
    
    0 讨论(0)
  • 2020-12-11 15:35

    Try this..

    String s="";
    
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        EditText t=(EditText)v;
        s=t.getText();  
        return false;
    }
    
    0 讨论(0)
  • 2020-12-11 15:41

    If you don't have a KeyEvent object you can use this on the keycode :

    public void onKey(int primaryCode, int[] keyCodes) {
         char c = Character.toChars(primaryCode)[0];
    }
    
    0 讨论(0)
  • 2020-12-11 15:44

    Use

    String.fromCharCode();
    

    String.fromCharCode(65,66,67) returns ABC.

    See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode .

    0 讨论(0)
  • 2020-12-11 15:47

    Use event.getNumber().

    0 讨论(0)
提交回复
热议问题