A better option would be using enhanced for
loop, so you won't need the final int
variable nor the int
variable:
for (final CityDetail cityDetail : cityDetailsArray) {
OnClickListener rowClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
showDetailsView(cityDetail);
}
};
row.setOnClickListener(rowClickListener);
//rest of the loop
}
Note that when passing data from the current method to an anonymous class you need to use a final
variable since the anonymous inner class should not be able to modify the reference (on in case of a primitive, it's value).