non-final variable inside an inner class
<p>I try to create dynamically a ImageView and I want to pass this imageView as a parameter to a method into the listener.</p>

<pre><code>            ImageView imageView1 = new ImageView(LookActivity.this);

            imageView1.setOnTouchListener(new OnTouchListener() {

                    @Override
                    public boolean onTouch(View arg0, MotionEvent arg1) {
                        detectLocationAndShowPopUp(imageView1);
                        return true;
                    }
                })
</code></pre>

<p>But I'm taking the following error:<br>
                                                                                                                                     Cannot refer to a non-final variable imageView1 inside an inner class defined in a different method.</p>

<p>I don't want to declare the imageView as final. How can I overcome this problem?</p>
