Issue
I have a Vector with 14 buttons with the same click's functionality. How can i do to abstract the method?
I did this but doesn't works.
for(Button b: botonesAEncender)
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
textoRespuesta.append(b.getText());
b.setVisibility(View.INVISIBLE);
tap.start();
verificarVictoria();
botonesUsados.add(b);
}
});
on b said the error said: "Variable is accessed within inner class. Needs to be declared final"
Solution
Declared that variable as final ;
for(final Button b: botonesAEncender)
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
textoRespuesta.append(b.getText());
b.setVisibility(View.INVISIBLE);
tap.start();
verificarVictoria();
botonesUsados.add(b);
}
});
Answered By - Vishal Vaishnav
Answer Checked By - Cary Denson (JavaFixing Admin)