Increase a char value by one

前端 未结 6 2163
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 17:24

I have an app with an EditText and a button named \"forward\". All I want is just when I type \"a\" in the EditText and click the button, the word \"b\

6条回答
  •  花落未央
    2021-02-18 17:40

    A simpler way would be:

    char value = edt.getText().toString().charAt(0);
    edt.setText(Character.toString ((char) value+1));
    

    Here the value + 1 adds the decimal equivalent of the character and increments it by one.. Here is a small chart:

    enter image description here enter image description here

    Whats happens after 'z'? ... it wont crash.. see here for the full chart..

提交回复
热议问题