I'm trying to set an OnClickListener
to some elements in my Android app, these elements are dynamically defined and are not given id
s, but they are put in a LinearLayouts
which exists in an List
of LinearLayouts
, so I set the OnClickListener
as follows:
List<LinearLayout> inner_ver = setElemets(1);
for (LinearLayout l: inner_ver){
l.getChildAt(0).setOnClickListener(new OnClickListener() { // here's the syntax error
@Override
public void onClick(View v) {
l.getChildAt(1).setBackgroundResource(R.drawable.home_curtopen);
}
});
}
but I got the syntax error mentioned in the title with l
and I can't just declare it as final
cause then it assigns the changes only to the last element in the List
.