请帮助我,我从来没有理解过 ClickListener内部的 工作方式,所以:
我有自己的班级:
public class ItemFrame extends LinearLayout{
int item_id;
public ItemFrame(Context context){
super(context);
}
public int getItem_id() {
return item_id;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
}
}
我一字不差,加上一个点击听者:
ItemFrame myItemFrame = new ItemFrame(this);
myItemFrame.setOnClickListener(new OnClickListener(){
public void onClick(View v){
//ERROR HERE:
//Cannot refer to a non-final variable myItemFrame inside an inner class
//defined in a different method
//Quick fix: Change modifier of myItemFrame to final.
myItemFrame.setItemId(100);
}
});
So... My question is: How can i set a data tag of my class, inside the onClickListener??? If i change it to final as Eclipse says, i cant modify it since it is final. Does it make any sense ?