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 of this.

  • in second parameter 2, want shown. see in code have used message , code, can know message string has value of edittext have called inputone. don't want that, right? want value of textview resulttxt why using message?! replace message resulttext.gettext() value of textview want.

  • in last parameter, 3. length of toast message. how long want it? for. in code set long toast message think 3 seconds. if want shorter one, use toast.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

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -