title: How to close an already opened programmatically popup window in android?
body: <p>I seted an OnItemClickListener in my ListView which open a pop up window.
  However, when I click on another item on my list - another pop window is opened and I don't know how to get the already opened window so I can close it.
  Any help would be very appreciated!</p>
  
  <p>Here's my code that opens the pop up window:</p>
  
  <pre><code>list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
  
                  LayoutInflater layoutInflater
                          = (LayoutInflater)getBaseContext()
                          .getSystemService(LAYOUT_INFLATER_SERVICE);
                  View popupView =layoutInflater.inflate(R.layout.popup,null);
  
  
                  Object checkExistence = parent.getItemAtPosition(position);
                  int imgID = ctx.getResources().getIdentifier(checkExistence.toString().toLowerCase().replace(" ","_"), "drawable", ctx.getPackageName());
                  ImageView imageView = (ImageView) popupView.findViewById(R.id.img1);
  
                  imageView.setImageResource(imgID);
  
                  final PopupWindow popupWindow = new PopupWindow(
                          popupView,
                          Toolbar.LayoutParams.WRAP_CONTENT,
                          Toolbar.LayoutParams.WRAP_CONTENT);
  
                  Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
                  btnDismiss.setOnClickListener(new Button.OnClickListener(){
  
                      @Override
                      public void onClick(View v) {
                          // TODO Auto-generated method stub
                          popupWindow.dismiss();
                      }});
  
                  popupWindow.showAsDropDown(list, 300, -1250);
  
              }
          });
  </code></pre>