Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
}
like image 825
ram Avatar asked Jul 04 '11 11:07

ram


People also ask

How to convert number to char in js?

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.


3 Answers

char unicodeChar = (char)event.getUnicodeChar();
like image 60
Tod Avatar answered Oct 23 '22 07:10

Tod


Use event.getNumber().

like image 27
Dave Avatar answered Oct 23 '22 05:10

Dave


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];
}
like image 20
Raffy Avatar answered Oct 23 '22 05:10

Raffy