android - toast in Java, need to show the value of a textview -
i have resulttextview shows result of computation. pass value of resulttextview show in toast.
i have code: toast.maketext(mycalcactivity.this,message, toast.length_long).show()
;
but code showing value of firstnumbertxt type first number calculated instead. :(
button plusbtn = (button) findviewbyid(r.id.plusbutton1); plusbtn.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { edittext inputone = (edittext) findviewbyid(r.id.firstnumbertxt); string message = inputone.gettext().tostring(); edittext inputtwo = (edittext) findviewbyid(r.id.secondnumbertxt); string message2 = inputtwo.gettext().tostring(); int first = integer.parseint(message); int second = integer.parseint(message2); int sum = first + second; textview resulttxt = (textview) findviewbyid(r.id.resulttextview); resulttxt.settext("result " + sum); toast.maketext(mycalcactivity.this, message, toast.length_long).show(); } }); }
is there way can please?
i think starter, , copied code without knowing even. let me straight forward you.
//actual toast toast.maketext(mycalcactivity.this, message, toast.length_long).show(); // exaplaining toast toast.maketext(1, 2, 3).show();
in first parameter
1
, activity toast shown. see in code,mycalcactivity.this
means current activity because of input ofthis
.in second parameter
2
, want shown. see in code have usedmessage
, code, can know messagestring
has value ofedittext
have calledinputone
. don't want that, right? want value oftextview resulttxt
why usingmessage
?! replacemessage
resulttext.gettext()
value oftextview
want.in last parameter,
3
. length oftoast message
. how long want it? for. in code set long toast message think 3 seconds. if want shorter one, usetoast.length_short
or customized duration.
so @ end, wanted code.
toast.maketext(mycalcactivity.this, resulttxt.gettext().tostring(), toast.length_long) .show();
sorry taking long, loved you. started bottom. please next time search before ask, there lot of similar questions , answers explaining them this.
Comments
Post a Comment