Backspace & Deleting text from strings
in
Android Processing
•
2 months ago
Having some problems deleting text from a string i am using to create a text box on an Android, i attempted two similar methods. Can anyone advise what is wrong, I suspect the backspace key in android may not be called "BACKSPACE" or substring is not the correct way to delete something from a string.
If you know better functioning examples of text boxes and inputs for android please provide links.
METHOD 1:
void keyReleased() {
if (key != CODED) {
switch(key) {
case BACKSPACE:
textValue = textValue.substring(0,max(0,textValue.length()-1));
break;
case TAB:
textValue += " ";
break;
case ENTER:
case RETURN:
// comment out the following two lines to disable line-breaks
//typedText += "\n";
//break;
case ESC:
case DELETE:
break;
default:
textValue += key;
}
}
}
METHOD 2:
void keyReleased() {
if (textValue.length() < 25 && key!= CODED && key != BACKSPACE){
textValue += key;
}
else if(key == BACKSPACE && textValue.length() > 0){
textValue = textValue.substring (0,textValue.length()-1);
}
}
1