title: Disabling the back button for popup windows
body: <p>Based on a YouTube tutorial video (<a href="https://www.youtube.com/watch?v=wxqgtEewdfo" rel="nofollow">https://www.youtube.com/watch?v=wxqgtEewdfo</a>) that teaches how to create popup windows, I was wondering how to dismiss the popup with a <strong>touch event</strong> as opposed to the back button...</p>
  
  <p>Here's MainActivity:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      RelativeLayout relative = (RelativeLayout)findViewById(R.id.relativeTest);
  
      Button button = (Button)findViewById(R.id.button);
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().
                      getSystemService(LAYOUT_INFLATER_SERVICE);
              ViewGroup container = (ViewGroup) layoutInflater.inflate(R.layout.myLayout, null);
  
              PopupWindow popupWindow = new PopupWindow(container, AbsListView.LayoutParams.MATCH_PARENT,
                      AbsListView.LayoutParams.MATCH_PARENT, true);
              popupWindow.showAtLocation(relative, Gravity.CENTER, 0, 0);
  
              container.setOnTouchListener(new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      popupWindow.dismiss();
  
                      return true;
                  }
              });
          }
      });
  }
  
  @Override
  public void onBackPressed() {
      // I want the back button to be disabled for both MainActivity and the
      // popup window.
  }
  </code></pre>
  
  <p>... Should I place onBackPressed() elsewhere or would that even be possible?</p>
  
  <p>Thanks in advance.</p>