title: how to use a button to control the popupwindow show or dimiss?
body: <p>I want use a button to control the popupwindow, When I click the button, the popupwindow showing,and then click the button , the popupwindow dimiss.
  The following is my code:</p>
  
  <pre><code>@Override
  public void onClick(View v) {
      showPopupWindow();
  }
  
  /*** button control the PopupWindow ***/
  private void showPopupWindow() {
      View view = View.inflate(this, R.layout.popwindow_item, null);
      popupwindow = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
      if (popupwindow.isShowing()) {  
          popupwindow.dismiss();
      }else {
          popupwindow.setOutsideTouchable(true);
          popupwindow.setBackgroundDrawable(new BitmapDrawable());
          popupwindow.showAsDropDown(title);
      }
      viewOfPop(view);
  }
  </code></pre>
  
  <p>and the result is that when I click the button ,the popupwindow always showing,and won't dimiss.
  I also try to use a flag,<code>private boolean isShow = false;</code>,and when I click the button I will change the boolean value,but I don't kown how can I change the boolean value,the popupwindow is close when I click the outside of popupwindow. please help me ,thanks advanced!</p>