Idea . Use another final variable.
ImageView imageView1 = new ImageView(LookActivity.this); final ImageView finalImageView = imageView1; imageView1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { detectLocationAndShowPopUp(finalImageView); return true; } })
Idea two . Use an anonymous subclass of ImageView, then use the ImageView.this link.
ImageView imageView1 = new ImageView(LookActivity.this) {{ setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { detectLocationAndShowPopUp(ImageView.this); return true; } }};
source share