How to convert the keycode
into char
or string
??
Here is the example code:
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
//Log.d("EditText", "It's Working...!" + event.getAction());
if (event.getAction() == 0) {
switch (v.getId()) {
case R.id.editText1:
Log.d("EditText", "In editText1");
if (text1.length() == 3)
{
text2.setText();
text2.requestFocus();
}
break;
case R.id.editText2:
Log.d("EditText", "In editText2");
if (text2.length() == 0)
text1.requestFocus();
break;
}
}
return false;
}
To convert an integer to its character equivalent, add the character code of the letter a (97) to the integer and pass the result as a parameter to the String. fromCharacterCode() method. The String. fromCharCode will return the character equivalent of the integer.
char unicodeChar = (char)event.getUnicodeChar();
Use event.getNumber()
.
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With