I know this may seem very simple, but here is my problem:
I have an onclickevent listener that should infinitely increment the counter on click:
final int counter = 0;
myimageView2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
counter ++;
}
});
The problem is that I cannot call the counter from inside the onclick event if it is not set to final . However, since it is final, I can no longer change its value.
I tried to place the counter in the onclick event, i.e.:
myimageView2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int counter = 0;
counter ++;
}
});
However, clicking on it also resets the counter back to zero.
? , ,
onclick, , , . onclick , reset , .