android - Delete or backspace function. I created a button but cannot do a delete/backspace in my edittext -
i want delete characters in edittext 1 one. i've research quite bit there problems, please advise. sample code.
i created delete button "imagebutton buttondelete;"// xml imagebutton1
, edittext "edittext display;"
display = (edittext) findviewbyid(r.id.edittext1); buttondelete.setonclicklistener(new view.onclicklistener() { public void onclick() { // edit text characters string textinbox = display.gettext(): //remove last character// string newtext = textinbox.substring(0, textinbox.length()-1); // update edit text display.settext(newtext);
try this:
// edit text characters string textinbox = display.gettext().tostring(); if(textinbox.length() > 0) { //remove last character// string newtext = textinbox.substring(0, textinbox.length()-1); // update edit text display.settext(newtext); }
Comments
Post a Comment