you are currently passing another instance of View to PopupWindow and try to find the button in the difference instance using the same instance that you went through in PopupWindow to find the button. Change your code as:
LayoutInflater inflater = (LayoutInflater) MainActivity.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.about_popup, null, false); final PopupWindow pw = new PopupWindow(popupView,400,440, true); pw.showAtLocation(lv, Gravity.CENTER, 0, 0); Button close = (Button) popupView.findViewById(R.id.okbutton); close.setOnClickListener(new OnClickListener() { public void onClick(View popupView) { pw.dismiss(); } });
The second way is to use an instance of PopupWindow to find the button in the current window inside the bloat layout again for the button:
Button close = (Button) pw.findViewById(R.id.okbutton); close.setOnClickListener(new OnClickListener() { public void onClick(View popupView) { pw.dismiss(); } });
source share