title: Closing the Popup in Android
body: <p>I have the following function which calls a popup from a menu button click. It has an ok button to close the popup. But the <code>onclick</code> function is not initiated on a button press. Also, I need to close the popup when the back button is pressed.</p>
  
  <pre><code>    LayoutInflater inflater = (LayoutInflater) MainActivity.this
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.about_popup, null, false),400,440, true);
  
      pw.showAtLocation(lv, Gravity.CENTER, 0, 0);
      View popupView=inflater.inflate(R.layout.about_popup, null, false);
      Button close = (Button) popupView.findViewById(R.id.okbutton);
      close.setOnClickListener(new OnClickListener() {
  
        public void onClick(View popupView) {
          pw.dismiss();
        }
      });
  </code></pre>
  
  <p>Thanks</p>