View pview = inflater.inflate(R.layout.popup_example,(ViewGroup)findViewById(R.layout.main)); 
PopupWindow pw = new PopupWindow(pview); 
            pw.showAtLocation(v, Gravity.LEFT,0,0); 
            pw.update(8,-70,150,270); 
 
              //if onclick written here, it gives null pointer exception. 
            ImageButton img=(ImageButton)pview.findViewById(R.id.home); 
            img.setOnClickListener(new OnClickListener() 
            { 
                public void onClick(View v) 
                { 
                    Intent..... 
                } 
        });