android - setting up multiple buttons at once -
android - setting up multiple buttons at once -
so im trying create calculator (first app) instead of having each button setup itself, there away them @ once?
this how it's setup now:
final button button1 = (button) findviewbyid(r.id.button1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (decimal == true) { string onscr = string.valueof(firsttextview.gettext()); onscr = onscr + 1; firsttextview.settext(onscr); currentval+= 0.1; } else { if (currentval == 0) { firsttextview.settext("1"); currentval++; } else { string onscr = string.valueof(firsttextview.gettext()); onscr = onscr + 1; firsttextview.settext(onscr); } } } });
i managed working, want condense code.
such multiple button click listners... button btminus = (imagebutton)findviewbyid(r.id.btminus); btminus.setonclicklistener(this); button btplus = (imagebutton)findviewbyid(r.id.btplus); btplus.setonclicklistener(this);
then activity want implements onclicklistener , implemented method is:
public void onclick(view v) { switch (v.getid()) { case r.id.btplus: toast.maketext(getapplicationcontext(), "plus clicked" + "+", toast.length_short).show(); break; case r.id.btminus: toast.maketext(getapplicationcontext(),"minus clicked" + "-", toast.length_short).show(); break; default: break; } }
android button
Comments
Post a Comment