How to use the variable of one method in another method in Java(android) -


i retrieving value of textview

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.calculation);     textview heading = (textview) findviewbyid(r.id.paper_name);     ...... } 

i have method in same class

@override public void onclick(view v) {        int black_and_white_multiuplier = 4200;     int color_multiuplier = 6400;     switch (v.getid()) {         case r.id.btcalculate:         int multiplier = rbcolor.ischecked() ? color_multiuplier : black_and_white_multiuplier;         int column = integer.parseint((string) spcolumn.getselecteditem());         int inch = integer.parseint((string) spinch.getselecteditem());         tvamount.settext((multiplier * column * inch) + "");         break;     } } 

i want set value of color_multiuplier , black_and_white_multiuplier based on value of heading have got oncreate method. possible?

declare textview @ class level...

textview heading;  protected void oncreate(bundle savedinstancestate)     {           super.oncreate(savedinstancestate);         setcontentview(r.layout.calculation);          heading = (textview) findviewbyid(r.id.paper_name);         heading.settext("something");              ...... 

then access in onclick() method below...

@override public void onclick(view v) {         int black_and_white_multiuplier = 4200;      int color_multiuplier = 6400;     switch (v.getid())     {         case r.id.btcalculate:              int multiplier = 0;              if (heading.gettext().tostring.equals("something")) {                  multiplier = color_multiuplier;              } else {                  multiplier = black_and_white_multiuplier;              }              //int multiplier = rbcolor.ischecked() ? color_multiuplier             //        : black_and_white_multiuplier;             int column = integer.parseint((string) spcolumn                     .getselecteditem());             int inch = integer.parseint((string) spinch.getselecteditem());             tvamount.settext((multiplier * column * inch) + "");             break;     } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -