title: Android ClickListeners not firing from a PopupWindow
body: <p>I've got a popupWindow that is triggered from the Activity Bar in Main Event. The buttons in the popup window are not triggering their respective listeners in showPopup(). Much of this popupWindow structure works fine when initiated from a fragment.  I cannot identify the root cause of this. Any suggestions? Thanks.</p>
  
  <pre><code>public class MainActivity extends Activity{
  private final static String TAB_KEY_INDEX = "TAB_KEY";
  public static Context appContext;
  private PopupWindow popupWindow;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      appContext = getApplicationContext();
      //put Actionbar in tab mode     
      ActionBar actionBar = getActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);            
      //set titles for tabs
      ActionBar.Tab tab1 = actionBar.newTab().setText("Tab1");
      //create instances of each of the fragments
      Fragment tab1Fragment = new Tab1Fragment();
      //attach those fragment instances to their respective tabs
      tab1.setTabListener(new MyTabsListener(tab1Fragment));
      //add each tab to the ActionBar
      actionBar.addTab(tab1);
      if (savedInstanceState == null){//...do nothing                     
      }else if (savedInstanceState != null){
      actionBar.setSelectedNavigationItem(savedInstanceState.getInt(TAB_KEY_INDEX,0));
      }
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch(item.getItemId()) {
          case R.id.menuitem_popup:
              showPopup();
              return true;
      }return false;
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu){
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.main, menu);
      return true;
  }
  @Override
  protected void onSaveInstanceState(Bundle outState){
      super.onSaveInstanceState(outState);
      outState.putInt(TAB_KEY_INDEX, getActionBar().getSelectedNavigationIndex());
  }   
  private void showPopup() { 
      Button btnDismiss, btnSaveRecord;
      try { 
      LayoutInflater layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);   
      View layout = layoutInflater.inflate(R.layout.popup_layout, null);
      popupWindow = new PopupWindow(layout, 580, 500, true); 
      popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 40);
  
      btnDismiss=(Button)MainActivity.this.findViewById(R.id.btnDismissxml);
      btnDismiss.setOnClickListener(new OnClickListener() {
          //@Override
          public void onClick(View arg0) {
              popupWindow.dismiss();
          }
      });
      btnSaveRecord=(Button)MainActivity.this.findViewById(R.id.btnSaveRecordxml);
      btnSaveRecord.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View arg0) {
              saveRecord();
          }
      });
      } catch (Exception e) { 
      e.printStackTrace(); 
      } 
      }
  public void saveRecord(){
      Toast.makeText(MainActivity.this.getApplicationContext(), "Event saveRecord() triggered.", Toast.LENGTH_SHORT).show();      
  }
  }   
  </code></pre>
  
  <p>Here's popup_layout.xml per request. Thanks.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:orientation="vertical" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:gravity="center_horizontal"
  android:background="@drawable/customborder"&gt; 
  &lt;TableRow&gt;
  &lt;TextView
      android:id="@+id/tv"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="This is Fragment3" /&gt;
  &lt;/TableRow&gt;
  
  &lt;TableRow&gt;  
   &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Species:" /&gt;
  &lt;EditText 
          android:id="@+id/textboxSpeciesxml"
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"   
                      android:layout_span="3"
          android:text="(table is empty)"/&gt; 
  
    &lt;/TableRow&gt; 
  
      &lt;TableRow&gt;
            &lt;Button
              android:id="@+id/btnSaveRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="SAVE" /&gt;
            &lt;Button
              android:id="@+id/btnUpdateRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="UPDATE" /&gt;
            &lt;Button
              android:id="@+id/btnDeleteRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="DELETE" /&gt;
            &lt;Button
              android:id="@+id/btnClearFormxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="CLEAR" /&gt;
           &lt;/TableRow&gt;
      &lt;TableRow&gt;
            &lt;Button
              android:id="@+id/btnFirstRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/pszFirstRecordButton"/&gt;
            &lt;Button
              android:id="@+id/btnPreviousRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/pszPreviousRecordButton"/&gt;
            &lt;Button
              android:id="@+id/btnNextRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/pszNextRecordButton"/&gt;
            &lt;Button
              android:id="@+id/btnLastRecordxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="@string/pszLastRecordButton"/&gt;
           &lt;/TableRow&gt;
      &lt;TableRow&gt;
          &lt;Button
              android:id="@+id/btnPurgeTablexml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_span="2"
              android:text="Purge Table!" /&gt;
            &lt;Button
              android:id="@+id/btnDismissxml"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
                          android:layout_column="3"
              android:text="Dismiss" /&gt;
      &lt;/TableRow&gt;
  &lt;/TableLayout&gt;    
  </code></pre>