How to convert the keycode
into char
or string
??
Here is the example code:
public boolean onK
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()+"");
char unicodeChar = (char)event.getUnicodeChar();
Try this..
String s="";
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
EditText t=(EditText)v;
s=t.getText();
return false;
}
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];
}
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 .
Use event.getNumber().