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

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -