java - Inner class - final variable can't be looped? -


i'm trying make loop gives each button method parameter dependent on button is. keep getting error:

i not final variable - must if nested in inner class.

for (int = 0; < 14; i++) {     buttons[i].setonclicklistener(new button.onclicklistener() {         public void onclick(view v) {             // issue value here             move.makemove(move.cups.get(i);             updatebuttons();         }     });     currentcup = nextcup; } 

try way:

for (int = 0; < 14; i++) {     final int currenti = i;     buttons[i].setonclicklistener(new button.onclicklistener() {         public void onclick(view v) {             // issue value here             move.makemove(move.cups.get(currenti);             updatebuttons();         }     });     currentcup = nextcup;  } 

Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -