While making an android app I encountered and issue regarding accessing a non final variable from an inner class. used This as a reference.
I wanted to ask what is the "proper" and efficient way to do this? my two solutions are below:
for (Button b : buttonArray) {
final Button bb = b;
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text.append(bb.getText().toString());
//Appending "1".."0" to a textView
}
});
}
OR
for (final Button b : buttonArray) {...}
//please feel free to suggest a better way. I will try to use lambda expressions to beautify the code later