```
for (int i=0; i<pages; i++) {
        ImageView img=new ImageView(this);
             ...

        img.setOnClickListener(new OnClickListener() {
            @Override public void onClick(View v) {
                showpage(i);
                }

            }
        });

        FLall.addView(img);
    }

```

how can i do this in java? I get always **"Cannot refer to a non-final variable i inside an inner class defined in a different method"**