title: click outside of popup to dismiss it
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog">How to dismiss the dialog with click on outside of the dialog?</a>  </p>
  </blockquote>
  
  
  
  <p>How can I click outside of a popup to dismiss it? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>cell.setOnClickListener(new OnClickListener(){
  
      /*This code is in a separate class so I needed to use ctx as context 
      *and the string "layout_inflater" because it was not recognizing 
      *LAYOUT_INFLATER_SERVICE*/
  
      @Override
      public void onClick(View arg0) {LayoutInflater layoutInflater  = 
      (LayoutInflater)ctx.getSystemService("layout_inflater");  
      View popupView = layoutInflater.inflate(R.layout.popup_window, null); 
      final PopupWindow popupWindow = new PopupWindow(popupView, 
            LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT);
      popupWindow.showAtLocation(newParentLayout, Gravity.CENTER, 0, 0); 
      }
  </code></pre>
  
  <p>I've also tried adding all of this but no results. </p>
  
  <pre><code> popupWindow.setTouchable(true);
   popupWindow.setFocusable(true);
   popupWindow.setOutsideTouchable(true);
   Drawable bg = ctx.getResources().getDrawable(R.drawable.popup_bg);
   popupWindow.setBackgroundDrawable(bg);
  </code></pre>
  
  <p>I'm out of ideas. Any help?</p>
  
  <p>Edit to add: the main layout is a ViewPager/PagerAdapter if that would affect anything?</p>