android - Reading multiple screen clicks and displaying the same on edittext -


am new android, , building simple calculator app. want read multiple clicks made on screen (i.e numbers) , display same in edittext.

kindly find code below, in button's onclicklistener event, displaying numbers directly in edittext. piece of code, displayed numbers in edittext getting overwritten (i.e not getting appended). example when click '1', appears correctly, , next when click '2', appears '2', instead of "12". know logic wrong here, how can make characters append in edittext?

code:

    button00.setonclicklistener(new button.onclicklistener(){         @override         public void onclick(view v) {             // todo auto-generated method stub             edittext01.settext("0");         }     });      button01.setonclicklistener(new button.onclicklistener(){         @override         public void onclick(view v) {             // todo auto-generated method stub             edittext01.settext("1");         }     });      button02.setonclicklistener(new button.onclicklistener(){         @override         public void onclick(view v) {             // todo auto-generated method stub             edittext01.settext("2");         }     }); 

thanks in advance

settext() doesn't depend on in box previously, you'll have simple string concatenating:

string prevtext = edittext01.gettext().tostring(); edittext01.settext(prevtext + "2"); 

since gettext() returns editable, have convert string, after point, yeah, above each number. further optimize having class stringbuilder, , using stringbuilder.append() add , set value, above should work fine.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -