android - Buttons value to EditText? -
i have edittext , buttons phone caller numbers putted on every button settext on edittext why not writing on next each other..? when press 1 2 whole edit text 2 if clicked 3 2 deleted , 3 wroten want keyboard text on next each other
public class mainactivity extends activity implements view.onclicklistener { edittext phoneto; button btn,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12,btn99; textview textview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); phoneto = (edittext) findviewbyid(r.id.edittext2); btn = (button)findviewbyid(r.id.button); btn1 = (button)findviewbyid(r.id.btn1); btn2 = (button)findviewbyid(r.id.btn2); btn3 = (button)findviewbyid(r.id.btn3); btn4 = (button)findviewbyid(r.id.btn4); btn5 = (button)findviewbyid(r.id.btn5); btn6 = (button)findviewbyid(r.id.btn6); btn7 = (button)findviewbyid(r.id.btn7); btn8 = (button)findviewbyid(r.id.btn8); btn9 = (button)findviewbyid(r.id.btn9); btn10 = (button)findviewbyid(r.id.btn10); btn11 = (button)findviewbyid(r.id.btn11); btn12 = (button)findviewbyid(r.id.btn12); btn99 = (button)findviewbyid(r.id.btn99); phoneto.setselection(phoneto.gettext().length()); btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { makephonecall(view); } }); } public void makephonecall(view view) { try { string number = phoneto.gettext().tostring(); intent phoneintent = new intent(intent.action_call); phoneintent.setdata(uri.parse("tel:" + number)); if (activitycompat.checkselfpermission(mainactivity.this, manifest.permission.call_phone) != packagemanager.permission_granted) { return; } startactivity(phoneintent); } catch (android.content.activitynotfoundexception ex) { toast.maketext(mainactivity.this, "call failed, please try again later!", toast.length_short).show(); } } @override public void onclick(view v) { switch (v.getid()){ case r.id.btn1: phoneto.settext("1"); break; case r.id.btn2: phoneto.settext("2"); break; case r.id.btn3: phoneto.settext("3"); break; case r.id.btn4: phoneto.settext("4"); break; case r.id.btn5: phoneto.settext("5"); break; case r.id.btn6: phoneto.settext("6"); break; case r.id.btn7: phoneto.settext("7"); break; case r.id.btn8: phoneto.settext("8"); break; case r.id.btn9: phoneto.settext("9"); break; case r.id.btn10: phoneto.settext("0"); break; case r.id.btn11: phoneto.settext("*"); break; case r.id.btn12: phoneto.settext("#"); break; case r.id.btn99: string str=phoneto.gettext().tostring(); if (str.length() >1 ) { str = str.substring(0, str.length() - 1); phoneto.settext(str); } else if (str.length() <=1 ) { phoneto.settext(""); } break; } } }
your switch statement wrong, if got asking for.
you want make user write full number, using everytime the
phoneto.settext(number);
this means everytime edittext resetted number
value
use instead phoneto.append(mynumber);
hope helped
Comments
Post a Comment