java - Return 2 integers in a int function -
i have 2 classes.
in first class integers low
, high
needed.
in second class want declare , change low
, high
.
public class displaymessageactivity extends actionbaractivity { int low = 0; int high = 101;
this works fine - after following function run through, integers didn't change.
public int close (view v) { edittext low2 = (edittext) findviewbyid(r.id.edittext2); edittext high2 = (edittext) findviewbyid(r.id.edittext3); int low = integer.parseint(low2.gettext().tostring()); int high = integer.parseint(high2.gettext().tostring()); high ++; toast.maketext(getapplicationcontext(), "low: " + low +" high: "+high, toast.length_short).show(); if (low > high) { //you can ignore alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("false numbers"); builder.setmessage("you set lower number higher higher one."); builder.show(); } else { this.finish(); } return low; //i want return low , high - command not change low or high! }
edited code:
public class highandlow{ int high= 0; int low = 101; } public int[] close(view v){ edittext low2 = (edittext) findviewbyid(r.id.edittext2); edittext high2 = (edittext) findviewbyid(r.id.edittext3); low = integer.parseint(low2.gettext().tostring()); //cant find low high = integer.parseint(high2.gettext().tostring()); //cant find high high ++; toast.maketext(getapplicationcontext(), "low: " + low +" high: "+high, toast.length_short).show(); if (low > high) { alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("false numbers"); builder.setmessage("you set lower number higher higher one."); builder.show(); } else{ this.finish(); } return highandlow; //dont work }
why not create high , low integers properties of class? implement you're usual getters/setters. set them via close method, , them second class when needed first instantiated class.
Comments
Post a Comment