2
public void onListItemClick(ListView parent, View v, int position, long id) 
{         
  super.onListItemClick(parent, v, position, id);



 LayoutInflater inflater = (LayoutInflater)
   this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

 View popView = inflater.inflate(R.layout.offer_popup, null, false); 
 final PopupWindow pw = new PopupWindow(

   inflater.inflate(R.layout.offer_popup, null, false), 
   500, 
   600, 
   true);

pw.showAtLocation(this.findViewById(android.R.id.list), Gravity.CENTER, 0, 0);    

 ImageView closeimage=(ImageView) popView.findViewById(R.id.imageView2);
closeimage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pw.dismiss();
 }
 });

I have the above code, closeimage is valid, and exists, but I click on the closeimage the OnCLick function is Not firing.

lilzz
  • 5,243
  • 14
  • 59
  • 87

3 Answers3

1

What I see you created popView View object but into PopupWindow you inflated not your popView but R.layout.offer_popup layout. After that you're getting Image object from popView and bind click to it. That click should close PopupWindow which has nothing to do with popView object.

Maxim
  • 4,152
  • 8
  • 50
  • 77
  • I need that popView otherwise it couldn't find the imageView2. – lilzz Jan 10 '12 at 22:06
  • I ment, instead of inflating layout (inflater.inflate(R.layout.offer_popup, null, false)) instead of this, put there your popView. Popupwindow will have your view, you will be able to get the image, and image click should work. – Maxim Jan 10 '12 at 22:12
  • Try this: final PopupWindow pw = new PopupWindow(popView, 500, 600, true); – Maxim Jan 10 '12 at 22:15
0

I do not see any errors in this piece of code. Maybe you could test which element has focus within the view?

Also take a look at this: Android ImageView's onClickListener does not work

Kind regards, Bram

Community
  • 1
  • 1
Bram
  • 4,533
  • 6
  • 29
  • 41
0

Maybe your onClick event is intercepted by some other view.

Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146