java - Scope of final variable not visible to OnClickListener -


i beginner, i'm trying build calculator. have problem.

i write answer this:

ans += double.parsedouble(etresult.gettext().tostring()); outtest.settext("the answer " + ans); 

this in onclicklistenter. problem have communicate double ans, defined in beginning of project, if want communicate double need him final, if final cant change him in onclicklistener.

can me , tell me how can this? thanks.

use usual trick: instead of double ans = 0 declare final double[] ans = {0} , you'll able use ans[0] += ... inside handler code.


Comments

Post a Comment

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -

android - send complex objects as post php java -